Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package samplesimulation;
- import java.util.Random;
- import java.util.Scanner;
- public class SampleSimulation {
- static boolean craps() {
- Random random = new Random();
- boolean flag = false;
- int roll1, roll2;
- roll1 = random.nextInt(6) + 1;
- roll2 = random.nextInt(6) + 1;
- int sum = roll1 + roll2 + 2;
- System.out.println("Roll: " + roll1 + " + " + roll2 + " = " + sum);
- if (sum == 7 || sum == 13) {
- flag = true;
- } else if (sum == 2 || sum == 3 || sum == 12) {
- flag = false;
- } else {
- while (true) {
- roll1 = random.nextInt(6) + 1;
- roll2 = random.nextInt(6) + 1;
- int newSum = roll1 + roll2 + 2;
- System.out.println("Roll: " + roll1 + " + " + roll2 + " = " + newSum);
- if (newSum == sum) {
- flag = true;
- break;
- } else if (newSum == 7) {
- flag = false;
- break;
- }
- }
- }
- if (flag) {
- return true;
- } else {
- return false;
- }
- }
- public static void main(String[] args) {
- System.out.println("How many time you wanna play game.....");
- Scanner sc = new Scanner(System.in);
- int N = sc.nextInt(), win = 0;
- for (int i = 0; i < N; i++) {
- boolean flag = craps();
- if (flag) {
- System.out.println("You Win");
- win++;
- } else {
- System.out.println("You Lost");
- }
- }
- System.out.println();
- System.out.println("Total Win: " + win);
- System.out.println("Total Lose: " + (N - win));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement