I have to input a string with numbers ex: 1,2,3,4,5. That's a sample of the input, then I have to put that in an array of INT so I can sort it but is not working the way it should work.
package array;
import java.util.Scanner;
public class Array {
public static void main(String[] args) {
String input;
int length, count, size;
Scanner keyboard = new Scanner(System.in);
input = keyboard.next();
length = input.length();
size = length / 2;
int intarray[] = new int[size];
String strarray[] = new String[size];
strarray = input.split(",");
for (count = 0; count < intarray.length ; count++) {
intarray[count] = Integer.parseInt(strarray[count]);
}
for (int s : intarray) {
System.out.println(s);
}
}
}
See Question&Answers more detail:os