Skip to content

Commit 4f07881

Browse files
committed
recommand scanner method
1 parent 15e1ae9 commit 4f07881

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Others/Armstrong.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
*
1010
*/
1111
public class Armstrong {
12+
static Scanner scan;
1213
public static void main(String[] args) {
13-
Scanner scan = new Scanner(System.in);
14-
System.out.println("please enter the number");
15-
int n = scan.nextInt();
14+
scan = new Scanner(System.in);
15+
int n = inputInt("please enter the number");
1616
boolean isArmstrong = checkIfANumberIsAmstrongOrNot(n);
1717
if (isArmstrong) {
1818
System.out.println("the number is armstrong");
@@ -42,6 +42,9 @@ public static boolean checkIfANumberIsAmstrongOrNot(int number) {
4242
} else {
4343
return false;
4444
}
45-
45+
}
46+
private static int inputInt(String string) {
47+
System.out.print(string);
48+
return Integer.parseInt(scan.nextLine());
4649
}
4750
}

0 commit comments

Comments
 (0)