I need help with this code. it's basically a lotto program, but I only need to know how to get the 1st number right to do the rest. the user needs to be able to enter a number between 0 and 55. The program has to send an error message if the user enters a number less than or equal then zero and greater than or equal to 55, and an error message is needed for each. then after the error message is read the program has to allow the user to reenter the number. Then the program needs to bypass the error messages if the number entered is between 0 and 55 like it's supposed to be. it has to be done using a Do-while ad if-else statements. Each time I've enter a number that is between 0 and 55 the code goes ahead and beads the error messages anyway. How is this fixed in this code:

import java.util.Scanner;

public class FinalProgram
{
    public static void main(String[] args)
    {
Scanner keyboard = new Scanner(System.in);
    int number1 = 0,number2,number3,number4,number5, powerball;
    int numberCount = 0;
do
{
System.out.println("Enter a number between 0 and 55");
number1 = keyboard.nextInt();
if(number1 <= 0)
{
System.out.println("Invalid entry. The number must be greater than 0");
number1 = keyboard.nextInt();
}
else
if(number1 >= 55)
{
System.out.println("Invalid entry. The number must be less than 55");
number1 = keyboard.nextInt();
}
}while(number1 < 0 && number1 > 55);
System.out.println("Okay");
}
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

uh. never mind. I've solved a couple problems. I think I'll get it

This article has been dead for over six months. Start a new discussion instead.