0
how to convert a string into int array
for eg. INPUT: string st="123"; OUTPUT: int ar[]={1,2,3};
7 Respuestas
+ 2
In Java you can use something like that :
public class Program
{
    public static void main(String[] args) {
        String st = "123";
        int[] array = new int[3];
        for (int i = 0; i < 3; i++ ){
        array[i] = (st.charAt(i));
        System.out.println(array[i]-48);
        }
        
    }
}
Use the length of the String and so on.
+ 2
Ok you you are getting chars type from your String. The char value for 1 is 49, for two 50 and so on...
This way you get the correct value.
https://www.w3resource.com/java-exercises/basic/java-basic-exercise-41.php
+ 1
Julio Codesal  thanks ;)
0
Julio Codesal what is the logic behind the last line
System.out.println(array[I]-48);






