-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask 1 Java Codsoft
More file actions
58 lines (51 loc) · 1.68 KB
/
Task 1 Java Codsoft
File metadata and controls
58 lines (51 loc) · 1.68 KB
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
51
52
53
54
55
56
57
58
import java.util.Scanner;
class range{
public int genrate(int max, int min){
return (int) (Math.random()*(max-min+1)+min);
}
}
public class Number_Game{
public static void main(String[] args){
Scanner s=new Scanner(System.in);
range rg=new range();
int TA=0;
int win=0;
while(true){
System.out.println("Enter the minimum number:");
int min=s.nextInt();
System.out.println("Enter the maximum number:");
int max=s.nextInt();
s.nextLine();
int c=rg.genrate(max,min);
int A=0;
while(true){
System.out.println("Guesss a number between "+min+" and "+max);
int g=s.nextInt();
A++;
if(g>c){
System.out.println("Its Greater");
}
else if(g<c){
System.out.println("Its lower");
}
else{
System.out.println("Correct guess");
win++;
break;
}
}
TA=TA+A;
System.out.println("Attempt="+A);
System.out.println("Wins="+win);
double winrate=(double) win/TA*100;
System.out.printf("your winrate is %.2f%%\n",winrate);
System.out.println("Do you want to play again (y / n)");
String PA=s.next();
if(!PA.equalsIgnoreCase("y")){
s.close();
System.exit(0);
}
s.nextLine();
}
}
}