First of, hi I'm a new user here. Learning my first year of Java.
This is just an exam question which I couldn't solve but am eager to find the answer to.
int num[] = {121, 13, 34, 11, 22, 54};
Using the for loop and while loop
The user is to check for palindrome numbers within the array and output it as follows:
121 is a palindrome number
13 is a not palindrome number
34 is a not palindrome number
11 is a palindrome number
22 is a palindrome number
54 is a not palindrome number
Previous I was taught how to print a given integer in reverse
This allows me to print out the integer in reverse. But in this question I'm required to somehow save the integer generated from the while loop and compare it to the array.int num = 123456789
while (num > 0) {
System.out.print(num % 10);
num /= 10;
}
Here's what I did:
Seems like using Integer.toString causes all my num[i] to become 0.int num[] = {121, 13, 34, 11, 22, 54};
String check[] = new String[6];
String temp;
for (int i = 0; i < num.length; i++) {
while (num.[i] > 0) {
temp = Integer.toString(num[i] % 10);
check[i] = check[i] + temp;
num[i] /= 10;
} // end while loop
if (check[i] = Integer.toString(num[i]) {
System.out.println(num[i] + " is a palindrome number")
} else {
System.out.println(num[i] + " is not a palindrome number")
} // end for loop
P.S. I'm not sure if this is the right section to be asking this. If it's in the wrong section, would a Mod move it to the right one please.