Numbers into array!

So mainly my program is supposed to keep taking user input until the user inputs 0. The integer's the user inputs will be placed into an array (the first value being the first number, the second value being the second number etc..) until all the integers that the user inputs are placed in the array.

This is what I have so far:

import java.io.*;

import java.util.*;

publicclass TrivialApplication{

publicstaticvoid main(String args[])throws IOException{

int scores = 1;

int score_i;

int [] score_array =newint[200];

BufferedReader kinput =

new BufferedReader (new InputStreamReader (System.in));

System.out.println("Enter numbers:");

while (scores != 0){

try{

scores = Integer.parseInt(kinput.readLine());

for (score_i = 0; score_i < score_array.length; score_i++){

score_array[score_i] = scores;

}

}catch (NumberFormatException nfe){

System.out.print("\nNumbers only Please: ");

scores = Integer.parseInt(kinput.readLine());

}

}

while (scores == 0){

break;

}

}

}

It takes the user's input until the user inputs 0. The only problem is that all values of the array are equal to the last number inputed (which has to be 0 since that is what you use to stop it). I know that somehow I am rewriting the value of the user's input each time they input a new value but how can i prevent this?

Message was edited by:

RAWR-itsanONION

[2680 byte] By [RAWR-itsanONIONa] at [2007-11-27 6:31:44]
# 1

try {

scores = Integer.parseInt(kinput.readLine());

for (score_i = 0; score_i < score_array.length; score_i++) {

score_array[score_i] = scores;

}

} catch (NumberFormatException nfe) {

System.out.print("\nNumbers only Please: ");

scores = Integer.parseInt(kinput.readLine());

}

You read in a number, then (with the for loop) populate every value in the array with that one value. And your last while loop is completely useless.

CaptainMorgan08a at 2007-7-12 17:56:43 > top of Java-index,Java Essentials,Java Programming...
# 2

scores = Integer.parseInt(kinput.readLine());

This line in the catch is useless. Say the user does enter something that causes an exception. You get them to enter a number again. If it is not zero it goes around the loop again and expects yet another number to be entered. Thus throwing away the number entered in the catch statement.

floundera at 2007-7-12 17:56:43 > top of Java-index,Java Essentials,Java Programming...