I'm sure this is going to be really easy to figure out and might even be something like trying to use correct grammar (this has happened to me a few times), but I've stared at this code for hours upon hours and don't know why NetBeans says it's wrong.
There is an illegal start of type in my public class Main { and
identifier> expected on my import java.util.Scanner;
I had more issues but somehow fixed them while typing this.
Yes this is homework, my teacher came from Russia and I can't understand a word he says!!! ~Great way to spend $1,000~
This program will get an unknown number of numbers from the user and determine their average. The user will quit by entering -1 if I can get it right.
package javaapplication17;
import java.util.Scanner;
/**
*
* @author Bren
*/
public class Main {
/**
* @param args the command line arguments
*/
import java.util.Scanner; // Scanner class used for getting user input
public class AverageNumbers
{
// The main method that begins execution of Java application
public void main(String args[])
{
// variable declarations
int number;
int total = 0;
int count = 0;
double average;
// create Scanner to capture input from console
Scanner input = new Scanner(System.in);
// get initial user input
System.out.print("Enter a number (-1 to quit): ");
number = input.nextInt();
// calculate total sum and get user input until number = -1
while (number != -1)
{
count++;
total += number;
System.out.print("Enter a number (-1 to quit): ");
number = input.nextInt();
}
// Calculate the average
average = (double)total / count;
// Display average System.out.printf("The average is %.2f"n", average");
} // end method main
} // end class AverageNumbers
}