Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //melinda
- //1.8.15
- //Dice
- import java.util.*;
- public class Dice
- {
- 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 dieA=0;
- int dieb=0;
- 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;
- int seven=0;
- int eight=0;
- int nine=0;
- int ten =0;
- int eleven =0;
- int twelve=0;
- for (int i =1; i <= toss; i++){
- dieA=(int)(Math.random()*6+1);
- dieb=(int)(Math.random()*6+1);
- if (sum ==2)
- two++;
- else if (sum==3)
- three++;
- else if (sum==4)
- four++;
- else if (sum==5)
- five++;
- else if (sum ==6)
- six++;
- else if (sum==7)
- seven++;
- else if (sum==8)
- eight++;
- else if (sum==9)
- nine++;
- else if (sum ==10)
- ten++;
- else if (sum==11)
- eleven++;
- else if(sum==12)
- twelve++;
- }
- System.out.println("2==>" + two + "times" +((int)(two/ (double)toss*100))+"%");
- System.out.println("3==>" + three + "times" + ((int)(three/ (double)toss*100))+"%");
- System.out.println("4==>" + four + "times" +((int)(four/ (double)toss*100))+"%");
- System.out.println("5==>" + five + "times" +((int)(five/ (double)toss*100))+"%");
- System.out.println("6==>" + six + "times" +((int)(six/ (double)toss*100))+"%");
- System.out.println("7==>" + seven + "times" +((int)(seven/ (double)toss*100))+"%");
- System.out.println("8==>" + eight + "times" +((int)(eight/ (double)toss*100))+"%");
- System.out.println("9==>" + nine + "times" +((int)(nine/ (double)toss*100))+"%");
- System.out.println("10==>" + ten + "times" +((int)(ten/ (double)toss*100))+"%");
- System.out.println("11==>" + eleven + "times" +((int)(eleven/ (double)toss*100))+"%");
- System.out.println("12==>" + twelve + "times" +((int)(twelve/ (double)toss*100))+"%");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement