Programming Assignment #66
Code
/// Name: Dylan Sleeper
/// Period: 6
/// Program Name: guess
/// File Name: guess.java
/// Date Finished: 1/5/2016
import java.util.Random;
import java.util.Scanner;
public class guess{
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
int guesses = 0;
int guess = 0;
Random r = new Random();
int num = r.nextInt(100) + 1;
System.out.println("I'm thinking of a number between 1-100. You have 7 guesses.");
while(guesses < 7){
System.out.print("Guess: ");
guess = keyboard.nextInt();
if(guess < num){
System.out.println("Too low.");
}
else if(guess > num){
System.out.println("Too high");
}
else{
break;
}
}
if(guess == num){
System.out.println("Wow, you actually got it.");
}
else{
System.out.println("Sorry you didn't get it.");
}
}
}
Outputs