-
Notifications
You must be signed in to change notification settings - Fork 0
/
prac2.java
49 lines (43 loc) · 1015 Bytes
/
prac2.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
43
44
45
46
47
48
49
import java.util.*;
class prac2 {
// method with no parameter
public int throwcoin() {
Random rnd=new Random();
int c1=rnd.nextInt(2);
return c1;
}
// method with single parameter
public int throwdice() {
Random rnd= new Random();
int d1=rnd.nextInt(7);
return d1;
}
public static void main(String[] args) {
// create an object of Main
Main obj = new Main();
int a=obj.throwdice();
int b=obj.throwcoin();
int g=1;
while (g<5)
{
System.out.println("Dice: "+obj.throwdice());
System.out.println("Coin: "+obj.throwcoin());
int sum=a+b;
if (sum==7)
{
System.out.println("You won..!");
break;
}
if(sum<7)
{
System.out.println("Your point: "+sum);
sum+=sum;
}
if (sum==0)
{
System.out.println("Lost..!");
break;
}
}
}
}