Java多行输入不同数据

来源:互联网 发布:翻译官软件如何 编辑:程序博客网 时间:2024/06/07 02:00

要求:
第一行包含一个整数 n (1 <= n <= 50),表示学生的个数,接下来的一行,包含 n 个整数,按顺序表示每个学生的能力值 ai。接下来的一行包含两个整数,k 和 d

public static void method() throws IOException {        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));        String line = null;        while((line=br.readLine())!=null) {            int n = Integer.parseInt(line); //n个学生            int[] array = new int[n];       //n个整数            line = br.readLine();            String[] str = line.split(" ");            for(int i=0; i<n; i++) {                array[i] = Integer.parseInt(str[i]);            }            line = br.readLine();            String[] str2 = line.split(" ");            int k = Integer.parseInt(str2[0]);            int d = Integer.parseInt(str2[1]);        }    }
原创粉丝点击