Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class DiceToss
- {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- System.out.println("How many times will you roll the two dice?");
- int toss = input.nextInt();
- int sum, dieA, dieB;
- //counters needed to keep track o results
- int two =0;
- int three =0;
- int four =0;
- int five =0;
- int six=0;
- for (int i =1; i <= toss; i++){
- dieA=(int)(Math.random()*6+1);
- dieB=(int)(Math.random()*6+1);
- if (dieA ==2 || dieB==2)
- two++;
- if (dieA ==3 || dieB==3)
- three++;
- if (dieA ==4 || dieB==4)
- four++;
- if (dieA ==5 || dieB==5)
- five++;
- if (dieA ==6 || dieB==6)
- six++;
- sum = dieA + dieB;
- System.out.println(dieA + " and " + dieB);
- System.out.println("The sum of the two dice is " + sum);
- }
- if(two>=1)
- System.out.println("2==>" + two + " times " +((int)(two/ (double)toss*100))+"%");
- if(three>=1)
- System.out.println("3==>" + three + " times " + ((int)(three/ (double)toss*100))+"%");
- if(four>=1)
- System.out.println("4==>" + four + " times " +((int)(four/ (double)toss*100))+"%");
- if(five>=1)
- System.out.println("5==>" + five + " times " +((int)(five/ (double)toss*100))+"%");
- if(six>=1)
- System.out.println("6==>" + six + " times " +((int)(six/ (double)toss*100))+"%");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement