I have a string "1 2 3 4 5" to split it and save the numbers into separate variables I was reading and saw that it has to use a method called Split ... I tried to do but I could not.
How do I do this, and then how do I convert to int the results so that I can eg add up all the numbers ?? In short: I want to know how to convert an integer String to an int array. The code that gave error was this:
public class Main {
public static void main(String[] args) {
String x = ("1 2 3 4 5");
String array[] = new String[5];
int resultado[] = new String[5];
array = x.split (" ");
System.out.println(resultado[0]+resultado[1]+resultado[2]+resultado[3]+resultado[4]);
}
}