Assignment #57
Code
///Name: Conner Wygaerts
///Period: 6
///Project Name: HiLo
///File Name: HiLo.java
///Date Finished: 12/2/15
import java.util.Random;
import java.util.Scanner;
public class HiLo
{
public static void main ( String[] args )
{
Random r = new Random();
int response, x = 1 + r.nextInt(100);
Scanner keyboard = new Scanner(System.in);
System.out.print("I'm thinking of a number between 1-100. Try and guess it.");
response = keyboard.nextInt();
if (response == x)
{
System.out.println("Congrats! You guessed correctly.");
}
else if (response > x)
{
System.out.println("Sorry that is too high. I was thinking of " + x);
}
else
{
System.out.println("Sorry that is too low. I was thinking of " + x);
}
}
}
Picture of the output