Thursday 9 March 2023

JAVA program to find the reverse of a string value and check whether the given string is palindrome or not !

 //JAVA program to find the reverse of a string value and check whether the given string is palindrome or not

import java.util.*;

class ReverseString

{

public static void main(String[] args)

{

String str,rev="";

int l;


Scanner s=new Scanner(System.in);

System.out.println("enter the string value:");

str=s.nextLine();


l=str.length();

for(int i=l-1;i>=0;i--)

{

rev=rev+str.charAt(i);

}


System.out.println("The reverse is:"+rev);


if(str.equals(rev))

{

System.out.println("palindrome");

}

else

{

System.out.println("not palindrome");

}

}

}

Output :