Assignment # 58 and HiLo
Code
/// Name: Tommy Oyuntseren
/// Period: 7
/// Program Name: HiLo
/// File Name: HiLo.java
/// Date: 12/2/2015
import java.util.Scanner;
import java.util.Random;
public class HiLo
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
byte guess = 0;
byte SN = (byte)(1 + r.nextInt(100));
{
System.out.print("I'm thinking of a number from 1 to 100.Try to guess it: ");
guess = (byte) keyboard.nextInt();
}
System.out.println();
if(SN==guess) System.out.println("You guessed it! You must have cheated somehow!");
else if (SN < guess) System.out.println("Nope, you guessed too high! Answer was "+SN+".");
else System.out.println("Nope, you guessed too low! Answer was "+SN+".");
System.out.println();
}
}
Picture of the output