So I am in an intro class to Java. I'm trying to write my first program. It's a simple program that asks for a number(X) which equals the number of rounds to be completed. Next you run a while loop that adds the total score until X number of rounds have been completed. The textbook doesnt really answer my question. I'm declaring 3 integers. Do I declare these in the main method, or inside the while loop. We have not started using a Java editor yet, so i'm not sure how to check this. He wants us to write out the code, but i'm not sure where to declare these integers, and how its supposed to be properly written. Any help would be great, thanks!
public class Question2
{
public static void main (String [] args )
{
Keyboard kbd;
Kbd = new keyboard();
int n, tot, x;
System.out.println( “How many?”);
x = kbd.readInt();
}
while ( n < x )
{
System.out.println( “Enter a score”);
s = kbd.readInt();
tot = (tot + s);
n = (n + 1);
}
}
whileloop needs to exist inside an actual method, not just in a random place in the class declaration.javacommand, to see whether it compiles without error or not. You don't need a fancy IDE.Keyboardclass? Pretty sure it doesn't exist in the standard library. Are you sure you don't want to useScanner?