Assignment #66
Code
/// Gian Adoremos
/// Period: 7
/// Program Name: SixtySixth Program
/// File Name: LimitedHiLo.java
/// Date Finished: 12/7/2015
import java.util.Random;
import java.util.Scanner;
public class LimitedHiLo
{
public static void main( String [] args)
{
Scanner key = new Scanner(System.in);
Random r = new Random();
int d1= r.nextInt(100)+1,d2;
System.out.println("Number 1-100?");
d2 = key.nextInt();
int n=0;
while (n!=7 && d1!=d2)
{
if (d1 <= d2)
{
System.out.println("Too hight");
d2 = key.nextInt();
n++;
if (d1==d2)
System.out.println("Yep");
}
else if (d1>= d2)
{
System.out.println("Too low");
d2 = key.nextInt();
n++;
if (d1==d2)
System.out.println("Yep");
}
}
if (n>=7)
{
System.out.println("Too late");
}
}
}
Picture of the output