Java Text Cmp


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import javax.swing.JOptionPane;

public class a4 {
public static void main(String args[]) {
String str = JOptionPane.showInputDialog(null,"Enter a 5-digi integer");
int len = str.length();
int len2 = len;
String tmpStr = str;

boolean flag = true;
for(int i = 0; i < len; i++) {
if ( str.charAt(i) != tmpStr.charAt(--len2) ) {
flag = false; break;
}
}

String tmp = "";
if (!flag) {
tmp = "not";
}

JOptionPane.showMessageDialog(null, str + " is " + tmp + " a palindrome");
}
}