Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
50 lines (43 loc) · 957 Bytes

File metadata and controls

50 lines (43 loc) · 957 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.tutorial.five;
import java.util.Random;
import java.util.Scanner;
public class Excercise {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
System.out.println("Think of a number between 0 and 1000");
int noOfGuesses = 0;
int random = 0;
int randomOrigin = 0;
int randomBound = 1000;
while(noOfGuesses<10)
{
Random rd = new Random();
random = rd.nextInt(randomBound);
rd.ints(randomOrigin, randomBound);
System.out.println("Computer thought of: "+random);
int userInput = in.nextInt();
if(userInput == 1)
{
randomOrigin = random;
randomBound = 1000;
}
else if(userInput == 2)
{
randomOrigin = 0;
randomBound = random;
}
else
{
System.out.println("Computer Wins");
break;
}
noOfGuesses++;
}
if(noOfGuesses == 10)
{
System.out.println("User Wins");
}
in.close();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.