Repository navigation
Expand file tree
/
Copy pathNumberGame.java
More file actions
93 lines (83 loc) · 2.29 KB
/
Copy pathNumberGame.java
File metadata and controls
93 lines (83 loc) · 2.29 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//Task-1,Number Game with 3 rounds
import java.util.*;
class NumberGame
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int random = (int)(Math.random()*100)+1; //generate a random number
int guess;
int nooftries=0;
System.out.println("Welcome to number world where you can see all the numbers and alphabets");
System.out.println("Game Rules:1 st and 2nd round are almost same ,In round-1 you will have 5 trails to guess the correct number,in round-2 there will be only 3 trails to guess the number,round-3 contains basic math problem");
System.out.println("Round-1");
for(int i=0;i<=4;i++)
{
System.out.println("Enter your guess");
guess = sc.nextInt();
nooftries++;
if(guess < random)
{
System.out.println("Too low , Try again");
}
else if(guess > random)
{
System.out.println("Too high,Try again");
}
else
{
System.out.println("Congrats!!!!!,you are selected .. Round 1 selected,R-1 score = 3");
break;
}
}
System.out.println("no of tries = "+nooftries);
System.out.println("Random Integer in Round 1 (1-100):"+random);
//round2
System.out.println("Round 2");
int g1,n1=0;
random = random+5;
for(int s=0;s<=2;s++)
{
System.out.println("Enter your guess:");
g1=sc.nextInt();
n1++;
if(g1 < random)
{
System.out.println("Too low , Try again");
}
else if(g1 > random)
{
System.out.println("Too high,Try again");
}
else
{
System.out.println("Congrats!!!!!,you are selected .. Round 2 selected,R-2 score = 5");
break;
}
}
System.out.println("no of tries = "+n1);
System.out.println("Random Integer (1-100):"+random);
//round3
System.out.println("");
System.out.println("Round 3..Basic maths");
System.out.println("Note: In this round you need to solve the basic math problem,You can have only 1 trail");
int c,x,y,m;
System.out.println("c * 5 = 30");//basic maths
System.out.println("x + 20 = 36");
System.out.println("y /12 = 2");
System.out.println("m - 5 = 5");
System.out.println("Fill the blank with the correct answer: find c,x,y,m");
c= sc.nextInt();
x= sc.nextInt();
y= sc.nextInt();
m= sc.nextInt();
if(c==6 && x == 16 && y == 24 && m == 10)
{
System.out.println("Congrats!!,You made it,Round 3 Winner,R-3 score = 10");
}
else
{
System.out.println("Sorry, you didn't pass round 3 ,try again");
}
}
}