java-获取控制台输入(传统)

来源:互联网 发布:linux权限不够怎么办 编辑:程序博客网 时间:2024/06/07 22:31
public static void main(String[] args) {BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));try {String string=bufferedReader.readLine();System.out.println("hhhh"+string);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}

传统;以字符读入。跟读文件一样。



import java.util.Scanner;public class Main {    public static void main(String[] args) {        Scanner in = new Scanner(System.in);        while (in.hasNextInt()) {            int a = in.nextInt();            int b = in.nextInt();
//String c =in.nextLine();
            System.out.println(a + b);        }    }}


0 0
原创粉丝点击