import java.util.Random;
import java.util.Scanner;
public class GuessingGame {
public static void main(String[] args)
{
// Scanner Class
Scanner sc = new Scanner(System.in);
final int num = 10;
int randomNumber ; // The number user has to guess
int guess ; // The guess the user made
int count = 0 ; // The count the user has made
Scanner scan = new Scanner(System.in);
Random generator = new Random();
randomNumber = generator.nextInt(num)+1 ; // generates the Number from 1- 10
System.out.print("Please guess a random number from 1 -10 ");
guess = scan.nextInt();
while (randomNumber != guess) // Loop until user enters the right number
{
System.out.println("Sorry too high !");
if ( guess >randomNumber) {
} else if ( guess < randomNumber) {
System.out.println("Sorry too low");
}
System.out.print("Guess again !"); // User can guess again if the guessed Number was wrong
guess = scan.nextInt();
count ++; // if user guessed wrong it counts +1 for every try
}
System.out.println("you guessed the right number !");
System.out.println("you needed : "+ guess+"tries");
}
}
- when i enter a number my code tells me : Sorry too high ! Sorry too low! ( it should only tell me if the number is too high or too low)
- 1 definded arguments and my code has to check for the input. If the entered number is below argument 1 it has to say : sorry invalid try again. same with argument 2
- my code doesnt count how many tries the user needed corretly. 4."Your program takes the input mentioned above, checks for correctness, transforms both arguments in data type intand then generatestheNumber." how do i do this ?
Aucun commentaire:
Enregistrer un commentaire