Programming Assignment #61
Code
/// Name: Dylan Sleeper
/// Period: 6
/// Program Name: Monte
/// File Name: Monte.java
/// Date Finished: 1/4/2016
import java.util.Random;
import java.util.Scanner;
public class NumberGuessing{
public static void main(String[] args){
Random r = new Random();
int randomNum = r.nextInt(10) + 1;
boolean right = false;
Scanner keyboard = new Scanner(System.in);
System.out.println("I have chosen a number 1 through 10. Try to guess it.");
while(right == false){
System.out.print("Your guess: ");
int guess = keyboard.nextInt();
if(guess == randomNum){
System.out.println("You got it right!");
right = true;
}
else{
System.out.println("That's not right. Try again.");
}
}
}
}
Outputs