比如输入
24
39
0想把24,39保存到数组里,不包括0,怎么弄?

解决方案 »

  1.   

    public static void main(String[] args) {
    List<Integer> list = new ArrayList<Integer>();
    Scanner scanner = new Scanner(System.in);
    int temp = scanner.nextInt();

    while(temp != 0){
    list.add(temp);
    temp = scanner.nextInt();
    }
    //输出
    for(int i=0; i<list.size(); i++){
    System.out.println(list.get(i));
    } }
      

  2.   

    手写仅供参考List list=new ArrayList();
    Scanner s=new Scanner(System.in);
    while(s.next()){
       String str=s.next;
       if(str.equals("0"))
           break;
       list.add(str);
    }
    s.close();
      

  3.   

    为什么我List<Integer>会显示报错The type List is not generic; it cannot be parameterized with arguments <Integer>
      

  4.   

    你List导包导的对么?是java.util.List么?