Well, if you are reading them all individually, you could try something like this:
int[] array = new int[10];
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
for(int x=0; x<10; x++)
{
array[x] = Integer.parseInt(in.readLine());
}
Does that help?
if your input is for example
java ReadArrayInteger 12345
then you should read it from your main method such as
public static void main(String[] args)
{
String input = args[0];
int[] num = new int[input.length()];
for (int number=0; number < input.length(); number++) {
num[number] = Integer.parseInt(""+args[0].charAt(number));
}
for (int number=0; number < input.length(); number++) {
System.out.println("Index " +number+ " has " +num[number]);
}
}
well, this only does separate single characters as int from command line..
--
Nywled
Message was edited by:
Redxxiv
> I guess it doesn't matter
Actually it does matter. You can input the numbers in a variety of ways. All on one line with no spaces( as per your example). All on one line separated by spaces. Each number on a different line. You will need a slightly different algorithm for each method.