Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
44 lines (29 sloc) 778 Bytes
import java.util.Random;
import java.util.Scanner;
public class trial
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Random rand = new Random();
Scanner input = new Scanner(System.in);
int target = rand.nextInt(100)+1;
int guess;
while(true)
{
System.out.println("Please enter a number >> ");
guess = input.nextInt();
System.out.println("You have entered " + guess);
if (guess == target)
{
System.out.println("You got the right number!!");
break;
}
else if (guess < target)
System.out.println("Try another higher number");
else
System.out.println("Try a smaller number");
for (int i = 0; i < 10; i++);
System.out.println(rand.nextInt(100)+1);
}
}
You can’t perform that action at this time.