Can you please share you java sample code so that it will be easy for us to assit you build similar one in apex class. If you like to simply reverse the string you can go with the string reverse() method.
Hii All... this is the code
#include
#include
int main() {
char str[100], temp;
int i, j = 0;
printf("\nEnter the string :");
gets(str);
i = 0;
j = strlen(str) - 1;
while (i < j) {
temp = str[i];
str[i] = str[j];
str[j] = temp;
i++;
j--;
}
printf("\nReverse string is :%s", str);
return (0);
}
Hi, this is a little different, but I was able to convert Java to Apex to manipulate a string to tell whether or not the string is a palindrome (the same word backwards and forwards).
Java:
public class Palindrome
{
public static void main(String args[])
{
String original = "yasay";
String reverse = "";
for(int i = original.length() - 1; i >= 0; i--)
{
reverse = reverse + original.charAt(i);
}
if(original.equals(reverse))
{
System.out.println("String is Palindrome");
}
else
{
System.out.println("String is not Palindrome");
}
}
}
Apex:
public class Palindrome
{
public Palindrome (String original, String reverse) {
{
for(Integer i = original.length() - 1; i >= 0; i--)
{
reverse += original.substring(i, i+1);
}
if(original.equals(reverse))
{
System.debug('333 String is Palindrome');
}
else
{
System.debug('333 String is not Palindrome');
}
}
}
}
I tried Palindrome of string with Reverse function
public class Palindrome {
public void palindromeornot(String originalone){
string reverseone='';
reverseone = originalone.reverse();
if(originalone.equals(reverseone)){
system.debug('string is palindrome');
}
else{
system.debug('string is not palindrome');
}
}
}
but here is one more way Hope this helps!
Thanks
Prady01
Java:
Apex:
for Annoymous window hope this might help someone.
Hi Bittus,
if you find this answer is helpful for you then mark this as a best answer.String originalString = 'Hello world';
String reversedString = '';
for (Integer i = originalString.length(); i > 0; i--) {
reversedString += originalString.substring(i-1,i);
}
System.debug('Reversed string : ' + reversedString);
public class BasicProgramming1 {
public static void myMethod1(){
String Dataforcheck= 'PQRST';
String revStr = ' ';
for (Integer i = Dataforcheck.length()-1; i >= 0; i--)
{
revStr = revStr + Dataforcheck.substring(i, i+1);
}
system.debug(revStr );
}
}
// Run in EAW
BasicProgramming1.myMethod1();