Note that there are some explanatory texts on larger screens.

plurals
  1. POReturning a Variable from a Separate Method, but I still get errors
    primarykey
    data
    text
    <p>Hello stackoverflow community. Currently I'm new to java and I'm trying to figure out how to module program. For whatever reason when I return the variable averageScore, it gives me an error for that variable in the main method. Any help would be appreciated.</p> <pre><code>public class Program4 { public static void main(String[ ] args) { EasyReader console = new EasyReader(); //Connect to EasyReader.class System.out.print("Enter the score from game 1: "); double score1 = console.readDouble(); //Reads the user input for game 1 System.out.print("Enter the score from game 2: "); double score2 = console.readDouble(); //Reads the user input for game 2 System.out.print("Enter the score from game 3: "); double score3 = console.readDouble(); //Reads the user input for game 3 average(score1, score2, score3); displayScores(score1, score2, score3, averageScore); } public static void average(double score1, double score2, double score3) { double averageScore = ((double)score1+score2+score3)/3; //Divides miles by gallons getAverage(); } public static double getAverage() { return new averageScore; } public static void displayScores(double score1, double score2, double score3, double averageScore) { System.out.println("Game 1 Score: " + score1 + " points"); //Prints score 1 System.out.println("Game 2 Score: " + score2 + " points"); //Prints score 2 System.out.println("Game 3 Score: " + score3 + " points"); //Prints score 3 System.out.println("Average score: " + RoundDouble.roundDouble(averageScore, 2) + " points "); //Prints the average score and rounds it to 2 decimals } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload