-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCost breakdown
More file actions
30 lines (24 loc) · 969 Bytes
/
Copy pathCost breakdown
File metadata and controls
30 lines (24 loc) · 969 Bytes
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
import java.util.Scanner;
public class doloop {
public static void main(String[]args){
Scanner scan = new Scanner(System.in);
int rand = ((int)(Math.random()*100)) + 1;
int randTwo = ((int)(Math.random()*100)) + 1;
int correctGuess = ((rand + randTwo)/2);
System.out.print("guess a number from 1 to 100 that is in the middle "
+ "of two random numbers: ");
int guess = scan.nextInt();
do
{
if (guess > correctGuess){
System.out.print("your guess is high. Guess again: ");
guess = scan.nextInt();}
if (guess < correctGuess){
System.out.print("your guess is too low. Guess again: ");
guess = scan.nextInt();
}
}while (guess != correctGuess);
System.out.println (" you guessed the middle number correctly!. "
+ "the two numbers were");
}
}