There is an int value between 0 and MAX_VALUE. From this value (whatever it may be), you need to get each digit and output in the string format.

String.valueOf (val) - helps me to get any value in the String format, but how can I get not the whole number but separately, each subsequent digit?

    2 answers 2

    The number in the string, the string in the array, each element of the array is a digit.

    int numm=123; String[] array = String.valueOf(numm).split(""); // array[0] - 1 // array[1] - 2 // array[2] - 3 

    UPD for Java < 8 in the array The 0th element will be empty.

    • Thank you very much! UPD> on the 8th roby;) - FixDe
    • Yes, not at all, tick as an answer, so that it is clear that the issue is resolved. - Neodev

    If you need a random number, use the String.charAt() method:

     int num = ...; final String string = String.valueOf(num); final char ch = string.charAt(...); 

    It works faster than split , because it does not allocate space for arrays.

    If you need to get digit by digit, this method can be used in a loop:

     int num = ...; final String string = String.valueOf(num); for(int i = 0; i < string.length(); i++) { final char ch = string.charAt(i); // ... } 
    • Upd. This option is correct and also correct. I would say a little more true. - FixDe