Advertisement
MelindaElezovic

Dice

Jan 12th, 2016
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. //melinda
  2. //1.8.15
  3. //Dice
  4. import java.util.*;
  5.  
  6. public class Dice
  7. {
  8.   public static void main(String[] args)
  9.   {
  10.     Scanner input = new Scanner(System.in);
  11.     System.out.println("How many times will you roll the two dice?");
  12.     int toss = input.nextInt();
  13.     int dieA=0;
  14.     int dieb=0;
  15.     int sum = dieA + dieb;
  16.     //counters needed to keep track o results
  17.     int two =0;
  18.     int three =0;
  19.     int four =0;
  20.     int five =0;
  21.     int six=0;
  22.     int seven=0;
  23.     int eight=0;
  24.     int nine=0;
  25.     int ten =0;
  26.     int eleven =0;
  27.     int twelve=0;
  28.    
  29.     for (int i =1; i <= toss; i++){
  30.       dieA=(int)(Math.random()*6+1);
  31.       dieb=(int)(Math.random()*6+1);
  32.       if (sum ==2)
  33.         two++;
  34.      else if (sum==3)
  35.         three++;
  36.      else if (sum==4)
  37.         four++;
  38.      else if (sum==5)
  39.         five++;
  40.      else if (sum ==6)
  41.         six++;
  42.      else if (sum==7)
  43.         seven++;
  44.      else if (sum==8)
  45.         eight++;
  46.      else if (sum==9)
  47.         nine++;
  48.      else if (sum ==10)
  49.         ten++;
  50.      else if (sum==11)
  51.         eleven++;
  52.      else if(sum==12)
  53.         twelve++;
  54.     }
  55.     System.out.println("2==>" + two + "times" +((int)(two/ (double)toss*100))+"%");
  56.     System.out.println("3==>" + three + "times" + ((int)(three/ (double)toss*100))+"%");
  57.     System.out.println("4==>" + four + "times" +((int)(four/ (double)toss*100))+"%");
  58.     System.out.println("5==>" + five + "times" +((int)(five/ (double)toss*100))+"%");
  59.     System.out.println("6==>" + six + "times" +((int)(six/ (double)toss*100))+"%");
  60.     System.out.println("7==>" + seven + "times" +((int)(seven/ (double)toss*100))+"%");
  61.     System.out.println("8==>" + eight + "times" +((int)(eight/ (double)toss*100))+"%");
  62.     System.out.println("9==>" + nine + "times" +((int)(nine/ (double)toss*100))+"%");
  63.     System.out.println("10==>" + ten + "times" +((int)(ten/ (double)toss*100))+"%");
  64.     System.out.println("11==>" + eleven + "times" +((int)(eleven/ (double)toss*100))+"%");
  65.     System.out.println("12==>" + twelve + "times" +((int)(twelve/ (double)toss*100))+"%");
  66.   }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement