0

How to make a java code that will ask user the number of times that user wants to print word "eggs"and then ask to do it again

How to make a java code that will ask user the number of times that user wants to print word "eggs"and then print the word "eggs" as much times as the number inserted and then ask the user if he wants to start again.

16th Dec 2016, 6:35 PM
Timo
Timo - avatar
3 Réponses
+ 2
//you must first create a scanner to get the user's input Scanner sc=new Scanner(System.in); //then ask for the eggs System.out.println("ask for eggs"); int Noeggs=sc.nextInt(); //number of eggs for(int i=0;i<Noeggs; i++){ // create a loop to print eggs as many times as the user asks System. out. println("eggs"); } System. out. println("type 1 if you want to repeat or 2 if you don't"); int t=sc.nextInt; it should look something like that. If you want the program to rerun automatically then put it into a loop and run while(t==1)
16th Dec 2016, 9:12 PM
Fanis Spirou
Fanis Spirou - avatar
0
Begin by printing eggs once Then use a loop to print lets say 10 times Tell me after you have done this we continue
16th Dec 2016, 9:04 PM
Agaba Ivan
Agaba Ivan - avatar
0
29th Nov 2021, 1:05 PM
Mark Cabrera
Mark Cabrera - avatar