hi! this is my first time one a forum and learning code, so please bear with me.
I was told to write a program which generates a random number between 0 to 5 *including 5*
and give the user 3 chances to guess this number:
If the user enters a wrong number within 0 to 5, the user has lost one opportunity.
If the user enters a number out of range, the program should prompt the user to enter a number within the range
If the user has 3 unsuccessful attempts, the program will print the number.
i was also instructed to use
Random randomNumber=new Random();
int i= randomNumber.nextInt(6)
i have attempted it and this is what i have so far.
package assignment7; import java.util.Random; import java.util.Scanner; public class Exercise1 { public static void main(String[] args) { Random randomNumber=new Random(); Scanner scan=new Scanner(System.in); int randomNumber,guessNumber; randomNumber=randomGenerator.nextInt(4); System.out.print("Guess the random number: " + "\n" + "you get three tries"); guessNumber=scan.nextInt(); for(int randomNumber;randomNumber<=4;randomNumber++) randomNumber=randomNumber<=4; } }