-1

I tried to make sure if the user entire statement is symmetric or not by trying this code but it's not working how can i compare the last character with the last one ?

  public static void main(String[] args) {

Scanner s=new Scanner (System.in);
    System.out.println("plz enter your string ");
    String UserEntier=s.nextLine();
    int j=UserEntier.length();
    for (int i=0;i<j;i++){
    if (UserEntier.charAt(i)==UserEntier.charAt(j));
    {System.out.println(UserEntier.charAt(i)+UserEntier.charAt(j));j--;}
    else
    System.out.println("not  a symmetric statement");}}
Abdalla
  • 3
  • 3

2 Answers2

1

To answer the question in the title:

String s; // your string
String another; // some other string
if ("someStringValue".equals(s)) {...}
if (another.equals(s)) {...}
if (another.equalsIgnoreCase(s)) {...} // compare without casing

Note your string should be initialized and contain a value. If you can't guarantee that it isn't null, then you should be passing that value to the argument of the equals call.

Also take note of your code formatting:

if (/* some boolean */);
{ /* action */; }

Your if statement will not be tied to any code block, because you end it prematurely with the ;. You should not put one after the statement itself. As it is right now, action will always be executed. An example of what this should look like:

if (/* some boolean */) {
    /* action */;
}
Rogue
  • 11,105
  • 5
  • 45
  • 71
0

If its regarding checking whether the entered String is a palindrome or not then its been answered by someone here - String Symmetry Program

Community
  • 1
  • 1
Wanderer
  • 366
  • 2
  • 6
  • 18