-
Notifications
You must be signed in to change notification settings - Fork 0
/
PalindromeNumber.java
63 lines (51 loc) · 1.78 KB
/
PalindromeNumber.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
52
53
54
55
56
57
58
59
60
61
62
63
// Create a function isPalindrome with one int parameter number and Check if the number is palindrome number or not. If it is palindrome return true, otherwise return false.
// For example ,
// isPalindrome(121)-> should return true
// isPalindrome(12343)-> should return false because the reverse is 34321 and it is not equal to 12343.
// import java.util.*;
// public class PalindromeNumber {
// public static boolean isPalindrome(int number) {
// int reverse = 0, temp = number;
// while (temp != 0) {
// reverse = reverse * 10 + temp % 10;
// temp = temp / 10;
// }
// return number == reverse;
// }
// public static void main(String[] args) {
// Scanner sc = new Scanner(System.in);
// System.out.print("Enter a number: ");
// int number = sc.nextInt();
// if (isPalindrome(number))
// System.out.println(number + " is a palindrome number");
// else
// System.out.println(number + " is not a palindrome number");
// }
// }
import java.util.*;
public class PalindromeNumber
{
public static boolean isPalindrome (int number)
{
int reverse = 0, temp = number;
while (temp != 0)
{
reverse = reverse * 10 + temp % 10;
temp = temp / 10;
}
if (number == reverse)
return true;
else
return false;
}
public static void main (String[]args)
{
System.out.print("Enter The Number : ");
Scanner sc = new Scanner (System.in);
int number = sc.nextInt ();
if (isPalindrome (number))
System.out.println (number + " is a palindrome number");
else
System.out.println (number + " is not a palindrome number");
}
}