File tree 1 file changed +60
-0
lines changed
1 file changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Rajiv asked his friend to write a java code to check the given number is palindrom are not?
3
+ if the number is less than 9 or greater than 9999 than return "invalid input"
4
+
5
+ Sample 1:
6
+ Enter the number : 121
7
+ number is palindrome
8
+
9
+ Sample 2:
10
+ Enter the number : 122
11
+ number is not palindrome
12
+
13
+ Sample 3:
14
+ Enter the number : 7
15
+ invalid input
16
+
17
+ Input Format
18
+
19
+ first line of the input reads the number
20
+
21
+ Constraints
22
+
23
+ 9 < n > 9999
24
+
25
+ Output Format
26
+
27
+ prints whether the number is palindrome or not.
28
+ */
29
+ import java .io .*;
30
+ import java .util .*;
31
+
32
+ public class Solution {
33
+
34
+ public static void main (String [] args ) {
35
+ /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
36
+ Scanner sc = new Scanner (System .in );
37
+ int num = sc .nextInt ();
38
+ if (num > 9 && num <9999 )
39
+ {
40
+ int orignal =num ,reverse =0 ,remainder ;
41
+ while (num !=0 )
42
+ {
43
+ remainder = num %10 ;
44
+ reverse = reverse *10 +remainder ;
45
+ num /=10 ;
46
+ }
47
+ if (orignal ==reverse )
48
+ {
49
+ System .out .print ("number is palindrome" );
50
+ }
51
+ else {
52
+ System .out .print ("number is not palindrome" );
53
+ }
54
+ }
55
+ else
56
+ {
57
+ System .out .print ("invalid input" );
58
+ }
59
+ }
60
+ }
You can’t perform that action at this time.
0 commit comments