-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q_31.java
51 lines (39 loc) · 936 Bytes
/
Q_31.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package New;
import java.util.Scanner;
public class Q_31 {
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
// TODO Auto-generated method stub
int num;
boolean userInputCorrect=false;
//Validation for five digit number
do {
System.out.println("Enter num");
num=sc.nextInt();
if(Integer.toString(num).length()==5) {
break;
}
else {
System.out.println("This is not a five digit number");
}
}while(!userInputCorrect);
int reversed = 0;
int org=num;
while(num != 0) {
int digit = num % 10;
reversed = reversed * 10 + digit;
num /= 10;
}
if(reversed==org) {
System.out.println("Palindrome");
}
else {
System.out.println("Not Palindrome");
}
}
}
/*Output
Enter num
44554
Not Palindrome
*/