Java:如何在arraylist中编写计算数据?

and*_*d93 1 java arrays arraylist

大家好,我是Java的初学者,我在阵列和arraylist方面遇到了一些问题.我的主要问题是如何将计算,动态数据写入数组以及后来如何读取它?这是我奇怪的代码:

    public static void main(String[] args) {

    int yil, bolum = 0, kalan;
    Scanner klavye = new Scanner(System.in);
    ArrayList liste = new ArrayList();

    //or shall i use this? >> int[] liste = new int[10];

    System.out.println("Y?l Girin: "); // enter the 1453
    yil = klavye.nextInt();

    do{ // process makes 1453 separate then write in the array or arraylist. [1, 4, 5, 3]

    kalan = yil % 10;
    liste.add(kalan); //my problem starts in here. How can i add "kalan" into the "liste".
    bolum = yil / 10;
    yil = bolum;

    }while( bolum == 0 );

    System.out.println("Say?n?n Basamak Say?s?: " + liste.size()); //in here read the number of elements of the "liste" 
    klavye.close();
}
Run Code Online (Sandbox Code Playgroud)

编辑:

    //needs to be like that
    while( bolum != 0 ); 
    System.out.println("Say?n?n Basamak Say?s?: " + liste);
Run Code Online (Sandbox Code Playgroud)

Hun*_*len 5

我认为你很可能希望你的循环停止条件是:

while( bolum != 0)
Run Code Online (Sandbox Code Playgroud)

因为bolum只有0在您的号码中没有剩余的数字才能处理.另外,如上所述,可能是用户0在提示输入数字时输入的情况,因此您应该考虑到这一点.