Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Random;
- public class GuessNumber{
- public static void main(String[] args) {
- System.out.println("Welcome to the Guess the Number Game");
- System.out.println("++++++++++++++++++++++++++++++++++++");
- System.out.println("");
- int random, guess, attempts;
- Scanner sc = new Scanner(System.in);
- String choice = "y";
- Random generator = new Random();
- random = generator.nextInt(100) + 1;
- attempts = 1;
- System.out.println("I'm thinking of a number from 1 to 100.");
- System.out.println("Try to guess it");
- System.out.println("");
- System.out.print("Enter Number: ");
- guess = sc.nextInt();
- while (guess != random) {
- if (guess - random > 10)
- {
- System.out.println("Way too high! Guess Again.");
- System.out.println("");
- System.out.println("");
- System.out.print("Enter Number: ");
- attempts += 1;
- }
- else if (guess - random < 10)
- {
- System.out.println("Way too low! Guess Again.");
- System.out.println("");
- System.out.println("");
- System.out.print("Enter Number: ");
- attempts += 1;
- }
- else if (guess > random) {
- System.out.print("Too High! Guess again.");
- System.out.println("");
- System.out.println("");
- System.out.print("Enter Number: ");
- attempts += 1;
- }
- else {
- System.out.print("Too Low! Guess again.");
- System.out.println("");
- System.out.println("");
- System.out.print("Enter Number: ");
- attempts +=1;
- }
- guess = sc.nextInt();
- }
- if (attempts <=3){
- System.out.println("Great work! You are a mathematical wizard.");
- }else if(attempts >3 && attempts <=7){
- System.out.println("Not too bad! You've got some potential.");
- }else{
- System.out.println("What took you so long? Maybe you should take some lessons.");
- }
- System.out.println("You got it in " + attempts + " tries.");
- }
- }
Add Comment
Please, Sign In to add comment