-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCraps.java
More file actions
51 lines (51 loc) · 1.21 KB
/
Copy pathCraps.java
File metadata and controls
51 lines (51 loc) · 1.21 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
//Craps
import java.util.Random;
public class Craps {
public static void main(String args[]){
Random rndm = new Random();
//LOOP
int i;
for(i=0; i<=1000; i++){
int x = 1 + rndm.nextInt(6);
System.out.print("You rolled " + x + " + ");
int y = 1 + rndm.nextInt(6);
System.out.print(y + " = ");
//natural
int sum = x + y;
System.out.println(sum);
if (sum==7||sum==11){
System.out.println("you win!");
break;
}
//craps
else if (sum==2||sum==3||sum==12){
System.out.println("you lose!");
break;
}
//point established
else {
System.out.println("\nA point has been established!!\n");
//Second LOOP
int j;
for(j=0;j<100;j++){
int a = 1 + rndm.nextInt(6);
System.out.print("You rolled " + a + " + ");
int b = 1 + rndm.nextInt(6);
System.out.print(b + " = ");
int newSum = a + b;
System.out.println(newSum);
if
(newSum==7){
System.out.println("you lose!");
break;
}
else if (newSum==sum){
System.out.println("you win!");
break;
}
}
break;
}
}
}
}