-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCh06Q03.java
More file actions
executable file
·43 lines (41 loc) · 1.21 KB
/
Ch06Q03.java
File metadata and controls
executable file
·43 lines (41 loc) · 1.21 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
/* */ package ch06;
/* */
/* */ import java.util.Scanner;
/* */
/* */ public class Ch06Q03 {
/* */ public static void main(String[] args) {
/* 7 */ Scanner scanner = new Scanner(System.in);
/* 8 */ System.out.print("Please input a number: ");
/* 9 */ int number = scanner.nextInt();
/* */
/* 11 */ if (isPalindrome(number)) {
/* 12 */ System.out.println(number + " is a palindrome.");
/* */ } else {
/* */
/* 15 */ System.out.println(number + " is NOT a palindrome.");
/* */ }
/* */ }
/* */
/* */
/* */
/* */ public static int reverse(int number) {
/* 22 */ int rv = 0;
/* 23 */ while (number != 0) {
/* 24 */ rv *= 10;
/* 25 */ rv += number % 10;
/* 26 */ number /= 10;
/* */ }
/* 28 */ return rv;
/* */ }
/* */
/* */ public static boolean isPalindrome(int number) {
/* 32 */ if (number == reverse(number)) {
/* 33 */ return true;
/* */ }
/* 35 */ return false;
/* */ }
/* */ }
/* Location: /Volumes/TXS.128G/hope useful/practice/2020.jar!/ch06/Ch06Q03.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/