-
Notifications
You must be signed in to change notification settings - Fork 0
/
cosoft_problem_question1.java
42 lines (34 loc) · 1.15 KB
/
cosoft_problem_question1.java
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
//Task 1 NUUMBER GAME
import java.util.Scanner;
import java.util.Random;
public class cosoft_problem_questions {
public static void main(String[] args) {
int user_input , computer_input;
Scanner ab = new Scanner(System.in);
Random cd = new Random();
computer_input = cd.nextInt(1,100);
do {
System.out.println("Enter your guess number in between 1 to 100 : ");
user_input = ab.nextInt();
int diff = computer_input-user_input;
if (diff<0 && diff<=50)
{
System.out.println("You are too high.");
} else if (diff>0 && diff>=50) {
System.out.println("You are too low.");
}
else{
System.out.println(
"you are close."
);
}
}while (user_input!=computer_input);
if (user_input == computer_input){
System.out.println("You won the Guess ..Computer also guessed the same number as you did.");
}
else
{
System.out.println("Try again");
}
}
}