I'm trying to create a programme like this previous one I've made;
It simply gives a boolean true/false on if a string backwards is still spelt the same way.
I've created this using if statements, but would like too know if it is possible too create using only methods and loops, and if so how? I have looked for duplicates, and there are similar posts that achieve what I have below, but everything I find uses if else statements
Any help appreciated as always; thanks.
import java.util.*;
public class testingthingsv24 {
private static Scanner in;
public static void main(String args[])
{
in = new Scanner(System.in);
System.out.println("Please Enter Your String: ");
String n=in.nextLine();
System.out.println("Your String Was: "+n);
StringBuffer str=new StringBuffer(n);
StringBuffer str2=new StringBuffer(str.reverse());
String s2=new String(str2);
System.out.println("Reversed Is: "+str2);
if(n.equals(s2))
System.out.println("ITS A PALINDROME");
else
System.out.println("ITS NOT A PALINDROME");
}
}
Output:
Please Enter Your String:
dad
Your String Was: dad
Reversed Is: dad
ITS A PALINDROME