package com.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class MainRun {
public static void main(String[] args) {
try {
BufferedReader strin=new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入一个字符串:");
String str = strin.readLine();
System.out.println("第一个:"+str);
System.out.println("请输入第二个字符串:");
String str2 = strin.readLine();
System.out.println("第2个:"+str2);
} catch (IOException e) {
e.printStackTrace();
}
}
}
2.JDK5以后引入了 Java.util.Scanner;来处理控制台输入并得到响应的类型数据
package com.test;
import java.util.Scanner;
public class MainRun {
/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("输入第一个boolean值(true/false):");
if(sc.nextBoolean()){
System.out.println("输入布尔:真的");
}else{
System.out.println("输入布尔:假的");
}
System.out.println("输入第一个数字:");
System.out.println("输入数字:"+sc.nextInt());
System.out.println("输入一个字符串:");
System.out.println("输入字符串:"+sc.next());
System.out.println("输入一个长整型:");
System.out.println("输入长整型:"+sc.nextLong());
}
}