creating an array of interger

I'm kinda new to javaIf i want to read numbers from the command line and put them into an arrayfor eg%123455123431will becomearray of int [1,2,3,4,5,5,1,2,3,4,3,1]thanks in advance
[230 byte] By [chromosome21a] at [2007-10-3 4:10:22]
# 1
Are you reading that entire String or reading each number individually?
CaptainMorgan08a at 2007-7-14 22:10:37 > top of Java-index,Java Essentials,New To Java...
# 2
I guess it doesn't mattereither way is fine
chromosome21a at 2007-7-14 22:10:37 > top of Java-index,Java Essentials,New To Java...
# 3

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?

CaptainMorgan08a at 2007-7-14 22:10:37 > top of Java-index,Java Essentials,New To Java...
# 4

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

Redxxiva at 2007-7-14 22:10:37 > top of Java-index,Java Essentials,New To Java...
# 5

> 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.

floundera at 2007-7-14 22:10:37 > top of Java-index,Java Essentials,New To Java...