-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome.java
More file actions
34 lines (28 loc) · 872 Bytes
/
Copy pathPalindrome.java
File metadata and controls
34 lines (28 loc) · 872 Bytes
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
import java.util.Scanner;
public class Palindrome {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("welcome to palindrome number");
System.out.println("please enter your number:");
int num = input.nextInt();
boolean isPalindrome = isPalindrome(num);
if (isPalindrome) {
System.out.println("the number is palindrome");
}
else {
System.out.println("the number is not palindrome");
}
}
public static boolean isPalindrome(int num) {
return num == reverse(num);
}
public static int reverse(int num) {
int newNum = 0;
while(num>0) {
int digit = num % 10;
newNum = newNum * 10 + digit;
num/=10;
}
return newNum;
}
}