why this method returns only zeroes and what would make it work?
I'm struggling with the AskInfo method of the following assignment:
//Your task is to complete the program below by writing three methods
(askInfo, copyInfo
//and setArray). Program should ask for integers (max 100 integers) until
the users types
//in zero. Integers can vary from one to one hundred and they are stored
in an array that
//has 100 elements. Numbers are asked for with the askInfo method, which
receives the
//array with numbers as parameter. Method returns the number of integers.
The number zero
//is not saved in the array; it is merely used to stop giving input.
public static int askInfo(int[] tempArray) {
Scanner reader = new Scanner(System.in);
int i;
int tempA[] = new int [10];
for (i = 0; i < tempA.length; i++) {
System.out.print((i+1) + ". number: ");
int luku = reader.nextInt();
if (luku == 0) {
return i;
}
}
for (i = 0; i < tempA.length; i++) {
System.out.println(tempA[i]);
}
return i;
}
No comments:
Post a Comment