import java.util.Scanner;
Scanner scanner = new Scanner(System.in);
System.out.println("int type 입력 : ");
데이터타입 변수이름 = scanner.next+데이터타입();
int i = scanner.nextInt();
scanner.close();
💡 예시
import java.util.Scanner;
public class Main01 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("int type 입력 : ");
System.out.println("double type 입력 : ");
int i = scanner.nextInt();
double d = scanner.nextDouble();
System.out.println("int 결과 : " +i)
System.out.println("double 결과 : " + d);\
scanner.close();
}
}
💡 예시
import java.util.Scanner;
public class Main02 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("문자열 입력 : ");
String str1 = scanner.nextLine();
System.out.println(str1);
System.out.println("문자열 입력 : ");
String str2 = scanner.next();
System.out.println(str2);
scanner.close();
}
}
💡 결과