Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- public class ch13
- {
- public static void main (String[] args )
- {
- Scanner scan = new Scanner( System.in );
- Random rand = new Random();
- int r, g, x = 1;
- r = (rand.nextInt(10)+1);
- System.out.println("I am thinking of a number from 1 to 10");
- System.out.println(" You must guess what it is in 3 tries");
- System.out.println("Enter a guess: ");
- g = scan.nextInt();
- while ( x < 3 )
- {
- x = x + 1;
- if ( g <= r - 3 || g >= r + 3 )
- {
- System.out.println("Cold");
- }
- else if ( g == r - 2 || g == r + 2 )
- {
- System.out.println("Warm");
- }
- else if ( g == r - 1 || g == r + 1 )
- {
- System.out.println("Hot");
- }
- if ( g == r )
- {
- System.out.println("RIGHT!");
- System.out.println("You have won the game!");
- }
- else
- {
- System.out.println("Wrong! Guess again!");
- g = scan.nextInt();
- }
- if ( x == 3 && g != r )
- {
- System.out.println("The correct number was " + r);
- System.out.println("You have lost the game. You are now a loser");
- }
- else if ( x == 3 && g == r )
- {
- System.out.println("RIGHT!");
- System.out.println("You have won the game!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement