-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay11_prob2.java
More file actions
58 lines (46 loc) · 1.23 KB
/
Day11_prob2.java
File metadata and controls
58 lines (46 loc) · 1.23 KB
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
52
53
54
55
56
57
58
/*
Rajiv asked his friend to write a java code to check the given number is palindrom are not?
if the number is less than 9 or greater than 9999 than return "invalid input"
Sample 1:
Enter the number : 121
number is palindrome
Sample 2:
Enter the number : 122
number is not palindrome
Sample 3:
Enter the number : 7
invalid input
Input Format
first line of the input reads the number
Constraints
9 < n > 9999
Output Format
prints whether the number is palindrome or not.
*/
// kirtan jain
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.close();
if(n<9 || n>9999){
System.out.print("invalid input");
}
else{
int rev=n;
int m=0;
while(n>0){
m+=n%10;
m*=10;n/=10;
}
m/=10;
if(rev==m)
System.out.println("number is palindrome");
else
System.out.println("number is not palindrome");
}
}
}