How to get the separate digits of an int number?

前端 未结 30 1935
陌清茗
陌清茗 2020-11-22 03:03

I have numbers like 1100, 1002, 1022 etc. I would like to have the individual digits, for example for the first number 1100 I want to have 1, 1, 0, 0.

How can I get

30条回答
  •  长情又很酷
    2020-11-22 03:14

    see bellow my proposal with comments

              int size=i.toString().length(); // the length of the integer (i) we need to split;
               ArrayList li = new ArrayList(); // an ArrayList in whcih to store the resulting digits
    
            Boolean b=true; // control variable for the loop in which we will reatrive step by step the digits
            String number="1"; // here we will add the leading zero depending on the size of i
            int temp;  // the resulting digit will be kept by this temp variable
    
        for (int j=0; j

提交回复
热议问题