-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindromeChecker.java
More file actions
46 lines (36 loc) · 1.02 KB
/
palindromeChecker.java
File metadata and controls
46 lines (36 loc) · 1.02 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
/*
# check if an input integer is palindrome or not.
steps:
-> calls isPalindrome function with input
-> isPalindrome function calls numReserver function for the reversed number
-> then it compares input number with reversed number
-> if they are equal, then it returns true, unless returns false
*/
import java.util.Scanner;
public class Main
{
public static int numReserver (int num)
{
int reversedNum = 0;
for ( ; num != 0; num /= 10)
{
reversedNum *= 10;
reversedNum += num%10;
}
return reversedNum;
}
public static boolean isPalindrome (int num)
{
int reversedNum = numReserver (num);
if (reversedNum == num)
return true;
else
return false;
}
public static void main (String [] args)
{
Scanner sc = new Scanner (System.in);
int num = sc.nextInt();
System.out.print ("Palindrome: " + isPalindrome (num));
}
}