-1

I'm trying to write a code where I need to use three methods. The first method must use a nested while loop to create a multidimensional array that is 3x3 and will get the values from the command line. The second method needs top use nested for loops in order to calculate the average of the doubles in each row. And the final method needs to shows the result of those averages. I'm currently getting cannot final symbol error. What did I do wrong?

I created the method fillArray to have the values from the user be stored. The return value is all the values entered at the command line.

import java.util.Scanner; public class Scorer {

public static void main(String[] args) {
    fillArray();
    System.out.println(scores);
}

public static double [][] fillArray(){
    double [][] scores = new double [3][3];
    Scanner scnr = new Scanner(System.in);
    int col = 3;
    int row = 3;

    System.out.println("Enter your scores: ");

    int i = 0;
    while(i < scores[i].length){
        int j = 0;
        while(j < scores[i].length){
            scores[i][j] = scnr.nextDouble();
            j++;
        }
        i++;
        }
    return scores;
    }

}

The code should allow for 3 values to be entered for each column and then be able to calculate the average of each rows values and have those results displayed back.

irv528
  • 1
  • 1
  • `scores` isn't in scope. You need to create an `Array` and assign the return value of your method to it – GBlodgett Apr 14 '19 at 22:20
  • I thought I had created the array Scores at the beginning of the method. Is this not the right way? – irv528 Apr 14 '19 at 22:28
  • You did, but it was a local variable confined to the method. It isn't in scope outside of the method – GBlodgett Apr 14 '19 at 22:29
  • How would I go about that? Is there an example I can follow? – irv528 Apr 14 '19 at 22:35
  • Possible duplicate of [What does a "Cannot find symbol" compilation error mean?](https://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean) – GBlodgett Apr 14 '19 at 22:35
  • I would research variable scope and read tutorials such as [this](https://www.baeldung.com/java-variable-scope) one – GBlodgett Apr 14 '19 at 22:36

1 Answers1

-1
while(i < scores[i].length){

in the third interaction you will get a indexofboundsexception. I = 3 -> scores[3].length

System.out.println(scores);

score was not declared in the main method.

System.out.println(scores);

I've never tested this, but you're trying to print a vector. don't know if this work