通过 System.in 获取数据流,java.util.Scanner 工具将数据流转换为想要的数据
import java.io.IOException;
import java.util.Scanner;
public class Test1 {
public static void main(String[] args) throws IOException {
System.out.println("请输入数据:");// 友好提示
Scanner sc = new Scanner(System.in);//获取键盘输入
//返回int型
int nextInt = sc.nextInt();
System.out.println("你输入的是: " + nextInt);
//返回double型
double nextDouble = sc.nextDouble();
System.out.println("你输入的是: " + nextDouble);
//返回一串字符串
String nextLine = sc.nextLine();
System.out.println("你输入的是: " + nextLine);
}
}