Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class DiceRoll2
- {
- static Scanner scan= new Scanner(System.in);
- public static void main(String[]args)
- {
- int times=0;
- System.out.println("How many sides: ");
- int sides=scan.nextInt();
- System.out.println("How many rolls: ");
- int rolls=scan.nextInt();
- int[] outcomes = new int[rolls];
- for(int i=0;i<rolls;i++)
- {
- int a=((int)(Math.random()*sides)+1);
- outcomes[i]=a;
- System.out.println((i+1)+"-"+outcomes[i]);
- }
- int max=outcomes[0];
- for(int i=0;i<rolls;i++)
- {
- if(outcomes[i]>=max)
- max=outcomes[i];
- }
- for(int i=0;i<rolls;i++)
- {
- if(outcomes[i]==max)
- times+=1;
- }
- System.out.println("\nThe highest rolled was "+max+" and it rolled "+times+" time(s).");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement