-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberGame_task1.java
More file actions
76 lines (76 loc) · 1.86 KB
/
NumberGame_task1.java
File metadata and controls
76 lines (76 loc) · 1.86 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.util.Random;
import java.util.Scanner;
class NumberGame_task1
{
static int number;
static int game()
{
Scanner scan=new Scanner(System.in);
int life=10;
while(life>0)
{
System.out.println("\nAttempts: "+life+"\nGuess the number: ");
int n=scan.nextInt();
if(n==number)
{
System.out.println("\nCORRECT ANSWER!!!!!");
break;
}
int x=Math.abs(number-n);
if(x<=10)
{
System.out.println("VERY NEAR");
}
else
{
if(x<=20)
{
System.out.println("NEAR");
}
else
{
if(x<=30)
{
System.out.println("FAR");
}
else
{
System.out.println("VERY FAR");
}
}
}
if(number>n)
{
System.out.println("IT'S GREATER THAN "+n);
}
if(number<n)
{
System.out.println("IT'S SMALLER THAN "+n);
}
life--;
}
System.out.println("\nANSWER: "+number);
return life;
}
public static void main(String[] args)
{
System.out.println("NUMBER GAME\n");
Scanner scan=new Scanner(System.in);
Random r=new Random();
System.out.println("enter number of rounds: ");
int n=scan.nextInt();
int[] score=new int[n];
for(int i=0;i<n;i++)
{
System.out.println("\nROUND "+(i+1));
number=r.nextInt(100);
score[i]=game();
}
System.out.println("\nSCORE:");
for(int i=0;i<n;i++)
{
System.out.println("ROUND "+(i+1)+": "+score[i]+"/10");
}
System.out.print("\nGAME OVER");
}
}