Java 표준 입력 Scanner
Scanner를 쓰기 위해선
먼저 import java.util.Scanner로 외부 패키지에서
Scanner 클래스를 호출해야함
Scanner 변수 = new Scanner(System.in)로
새로운 객체생성
nextLine()
문자열 입력
nextInt()
정수 입력받기
nextDouble()
실수입력받기
import java.util.Scanner;
public class Note{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.println("x(int):");
int x = scan.nextInt();
System.out.println("y(String):");
String y = scan.nextLine();
System.out.println("z(double):");
double z= scan.nextDouble();
System.out.println("x:"+x);
System.out.println("y:"+y);
System.out.println("z:"+z);
}
}
결과
x(int):
5
y(String):
java
z(double):
5.6
x:5
y:java
z:5.6