import java.util.*;

public class Game{
public static void main(String arg[])
{

int[] a = new int[101];
int i;

for(i=1;i<a.length;i++)
{
 a[i]=i;
}

int lucky = (int)(Math.random()*100 );
System.out.println(" My lucky no. is "+lucky);
System.out.println();
System.out.println();
System.out.println();

int low=0;
int high=100;
int mid=0;

while(mid!=lucky)
{
 System.out.println(" Enter your guess between 1 and 100 ");

mid = (low+high)/2;
 System.out.println(mid);
 if(lucky == mid)
 {
 System.out.println(" This time your guess is right"+mid);
 }

 else if(lucky>mid)
 {
 System.out.println(" This time your guess is too low ");
 low=mid+1;
 }
 else
 {
 System.out.println(" This time your guess is too high ");
 high=mid-1;
 }
}

&nbsp;

}

}

&nbsp;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: