Explanation
I was given a task in my Grade 12 Computer Science class that just totally has me stumped. So far I have tried using a bunch of if statements (While i know that is not the best way of doing I though for sure it was going to work) but that didn't work. I then tried to use nested loops but that didn't work either here is the code that I created so far for this method.
Code (Note: Max=1000)
private static void totals2 (Scanner user_input,int max){
int[] num = new int[max];
int[] total=new int[10];
System.out.println("Welcome to totals\nThis method gathers input and displays the sum depending on which category they fall in");
System.out.println("Enter numbers from 0-99 only (Up to 1000 inputs)\nEnter any number outside of 0-99 to stop collecting\n");
for (int i = 0; i < num.length; i++) {
System.out.println("Please enter a number to be stored in index: " + i);
num[i] = user_input.nextInt();
if (num[i] < 0 || num[i] > 99) {
break;
}
}
for(int i = 0; i < 100; i +=10){
int j;
int k=(i/10)-1;
for(j=0 ;j<1000;j++){
if (num[j] <= i){
total[k]+= num[j];
}
}
System.out.println(total[k]);
}
}
Question
Create a procedure that will output the total of all numbers (in an array) entered less than 10, the total of all numbers entered less than 20, the total of all numbers entered less than 30, ... and the total of all numbers entered less than 100 (so 88 will be included in both totals for numbers less than 90 and less than 100).