자바 Scanner를 통한 유저인풋 받는법을 정리하였다.
Scanner scanner = new Scanner(System.in);
System.out.println("이름을 입력하세요");
String name = scanner.nextLine();
System.out.println("몇 살 인가요?");
int age = scanner.nextInt();
System.out.println("안녕 " + name + "야");
System.out.println("너는" + age + "살이야");
메서드 | 기능 |
nextBoolean() | Boolean 읽기 |
nextByte() | Byte 읽기 |
nextShort() | Short 읽기 |
nextLong() | Long 읽기 |
nextFloat() | Float 읽기 |
nextDouble() | Double 읽기 |
next() | string 읽기 | 띄어쓰기 뒷부분 읽지 않음 |
nextLine() | Line 읽기 |
nextInt() | Int 읽기 |