recommand scanner method

This commit is contained in:
SunggyuLee 2018-12-19 23:02:39 +09:00
parent 15e1ae9429
commit 4f07881c42

View File

@ -9,10 +9,10 @@ import java.util.Scanner;
* *
*/ */
public class Armstrong { public class Armstrong {
static Scanner scan;
public static void main(String[] args) { public static void main(String[] args) {
Scanner scan = new Scanner(System.in); scan = new Scanner(System.in);
System.out.println("please enter the number"); int n = inputInt("please enter the number");
int n = scan.nextInt();
boolean isArmstrong = checkIfANumberIsAmstrongOrNot(n); boolean isArmstrong = checkIfANumberIsAmstrongOrNot(n);
if (isArmstrong) { if (isArmstrong) {
System.out.println("the number is armstrong"); System.out.println("the number is armstrong");
@ -42,6 +42,9 @@ public class Armstrong {
} else { } else {
return false; return false;
} }
}
private static int inputInt(String string) {
System.out.print(string);
return Integer.parseInt(scan.nextLine());
} }
} }