-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPalindrome.java
47 lines (32 loc) · 858 Bytes
/
Palindrome.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
import java.util.Scanner;
public class Palindrome {
//reverse the number
public static int reverse(int number) {
int reverse = 0;
while (number != 0) {
reverse = reverse * 10;
reverse = reverse + number % 10;
number = number / 10;
}
return reverse;
}
//determine if number is a palindrome
public static boolean isPalindrome(int number) {
boolean isPali = true;
if (number == reverse(number)) {
isPali = true;
}
else if (number != reverse(number)) {
isPali = false;
}
return isPali;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//get user input
System.out.println("Please enter an integer: ");
int usernum = input.nextInt();
//print results
System.out.println("Is your number is a Palidrome number? " + isPalindrome(usernum));
}
}