Current location - Training Enrollment Network - Mathematics courses - How to judge palindromes with java?
How to judge palindromes with java?
System.out.println ("Please enter ...");

Scanner in = new scanner (system. in);

String number = in.next ();

System.out.println ("You entered"+number);

Boolean flag = true;

for(int I = 0; I< # NUMBER. Trim (). length()/2; i++){

//Compare the characters with index I with those with symmetric indexes to see if they are the same.

If (! String.valueOf(number.charAt(i))。 equals(string . value of(number . charat(number . trim()。 Length ()-I-1))) (

flag = false

Break;

}

}

If (logo) {

System.out.println ("is a palindrome");

} Otherwise {

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

}

There is no validity check on the input data. If necessary, you can check the number yourself, such as whether the number is positive or negative, and so on.