-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmontyHall.java
More file actions
32 lines (27 loc) · 906 Bytes
/
montyHall.java
File metadata and controls
32 lines (27 loc) · 906 Bytes
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
import java.util.Scanner;
import MontyHallStruc.*;
public class montyHall{
public static void main(){
Scanner in = new Scanner(System.in);
// Keep Gold in a random box;
int gold =(int) (Math.random()*10);
gold = gold%3 + 1;
// System.out.println("Correct is : " + gold);
int c = gold;
System.out.println("Choose a box: ");
int n = in.nextInt();
if(n != gold){
c = gold;
}else{
c = (n + 1)%3;
}
System.out.println("Computer Chosed " + c + " . Do u wanna Swapp??(y/n)");
if(in.next().charAt(0) == 'y'){
c += n;
n = c - n;
c = c - n;
System.out.println("Swapped");
}
System.out.println("Correct box is " + gold + " and you are " + n + " and computer is " + c);
}
}