Assignemnt #58 and HiLo
Code
/// name: Leila Ordukhani
/// period: 6
/// program name: Forty-Eighth Program
/// file name: HiLo.java
/// date finished: 11/30/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