import java.io.InputStreamReader;
import java.io.BufferedReader;
public class dNumberIsPalindrome {
public static void main(String args[]) {
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(in);
String num;
// get a number
System.out.println("Enter a number : ");
try {
num = reader.readLine();
} catch (Exception e) {
e.printStackTrace();
System.out.println("Out of memory");
return;
}
boolean isPalindrome = false;
char array[] = num.toCharArray();
int endIndex = array.length - 1;
for (int startIndex = 0; startIndex <= endIndex; ++startIndex, --endIndex) {
if (array[startIndex] != array[endIndex]) {
isPalindrome = false;
break;
}
isPalindrome = true;
}
System.out.println("Palindorme check for " + num + " is "
+ isPalindrome);
}
}
import java.io.BufferedReader;
public class dNumberIsPalindrome {
public static void main(String args[]) {
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(in);
String num;
// get a number
System.out.println("Enter a number : ");
try {
num = reader.readLine();
} catch (Exception e) {
e.printStackTrace();
System.out.println("Out of memory");
return;
}
boolean isPalindrome = false;
char array[] = num.toCharArray();
int endIndex = array.length - 1;
for (int startIndex = 0; startIndex <= endIndex; ++startIndex, --endIndex) {
if (array[startIndex] != array[endIndex]) {
isPalindrome = false;
break;
}
isPalindrome = true;
}
System.out.println("Palindorme check for " + num + " is "
+ isPalindrome);
}
}
No comments:
Post a Comment