从键盘输入若干个数字并且把输入的数字存入数组中(不能用集合类并且从键盘输入的数字可以是任意数即:可一是2 位数字,也可以是3或4位数)

解决方案 »

  1.   

    package Csdn;import java.io.*;public class ReadNum {
    public static void main(String args[]){
    int[] n = new int[100];
    System.out.println("Input how many number?");
    BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
    String s;
    int times=0;
    try {
    s = b.readLine();
    times =Integer.parseInt(s);
    } catch (IOException e1) {
    e1.printStackTrace();
    }

     
    for (int i = 0; i<times;i++){
    System.out.println("Input a number");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try {
    String str = br.readLine();
    n[i]=Integer.parseInt(str);
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();


    }
    }