Need help writing a while loop with a priming read in JAVA?

need to know if Im correct: Write a while loop (use a priming read) that counts the number of values entered by the user that are divisible by 3. The loop should terminate when the number entered by the user is negative. My code: int x = 0; Scanner keyboard = new Scanner(System.in); // is this the... show more need to know if Im correct:
Write a while loop (use a priming read) that counts the number of values entered by the user that are divisible by 3. The loop should terminate when the number entered by the user is negative.

My code:
int x = 0;
Scanner keyboard = new Scanner(System.in); // is this the priming lead
System.out.println("please enter a positive number ");
x = keyboard.nextInt();

while (x < 0)
{
System.out.println(" Please enter a positive number"); // is this the priming read?
x = keyboard.nextInt();
}

while (x >= 0)
{

if (x%3==0)
System.out.println(" The number " + x + " is divisible by 3");
else
System.out.println(" The number " + x + " is not divisible by 3");
System.out.println(" Please enter a number or enter a negative number to quite ");
number = keyboard.nextInt();
}


Please tell me if this is correct also
1 answer 1