Hi I am trying to teach myself Java as a hobby and I am basically learning from youtube and questions from java books
I came across this question below and I am stuck on a couple of things.
1) How do I get a yes/no response from the user until they enter n
2) How do I display the final results
I have tried to answer this question myself but I am stuck and could use a little assistance please
Write a program using a while loop which will ask the user to enter three Lotto numbers.
The program should then repeatedly ask the user if they wish to select three different Lotto
Numbers until they reply n, in which case the program will display the final 3 numbers.*/
import java.util.Scanner;
I came across this question below and I am stuck on a couple of things.
1) How do I get a yes/no response from the user until they enter n
2) How do I display the final results
I have tried to answer this question myself but I am stuck and could use a little assistance please
Write a program using a while loop which will ask the user to enter three Lotto numbers.
The program should then repeatedly ask the user if they wish to select three different Lotto
Numbers until they reply n, in which case the program will display the final 3 numbers.*/
import java.util.Scanner;
public class Question14
{
public static void main (String [] args)
{
Scanner kb = new Scanner(System.in);
int numChoice = 1; //store 3 number choices
int i = 1; //initiaize index counter i
System.out.println("Please enter lotto number between 1 and 40");
while (i <=3)// loop 3 times while i is less than 3
{
numChoice = kb.nextInt(); // get user input and store the value in numChoice
System.out.println(" Number " + i + " entered was " + numChoice);
i++;
if(i > 3)
System.out.println ("Would you like to enter 3 new numbers?");
}
}//end main
}//end of class