Originally Posted by
FrozenBoi
Waaaa!! mga master Java man di mu..
Update nko kng unsa wla pa n solve....
11-14-17-18-19-20-22-23-24.......
sa mga nka solve salamat jud kaayo..
c lord nai bhala ninyo... kbw nmu kng kinsa mu...
kuhaon nato nato ning tunga nga problem:
Code:
/*
* 19. Write a Java class called IsPalindrome, which defines a main() method
* that asks the user to enter a String s, and displays whether or not s is a
* palindrome. A palindrome is a String which reads the same forwards and
* backwards, such as "laval" or "stressed desserts".
*
* Code taken from my previous solution of problem #21
*
* @author bishop__
*/
import javax.swing.*;
import java.text.*;
class IsPalindrome {
public static void main( String[] args ) {
String s1, s2;
int result = 0, len, index1, index2;
s1 = JOptionPane.showInputDialog(null, "Enter a string:");
s2 = s1;
len = s1.length();
// improvement: string can be cut into half to speedup comparison
for (index1 = 0, index2 = len - 1; index1 < len; index1++, index2--) {
if (s1.charAt(index1) != s2.charAt(index2)) {
result = -1;
}
}
if (result == 0) {
JOptionPane.showMessageDialog(null, "Palindrome !");
} else {
JOptionPane.showMessageDialog(null, "Not Palindrome !");
}
}
}