Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class dice {
- public static void main(String[] args) {
- int argsamt = args.length;
- if (argsamt < 2) {
- System.out.println();
- System.out.println("Dice Roll Needs 2 Arguments");
- System.out.println();
- System.out.println("'java dice x y'");
- System.out.println();
- System.out.println("Where x is the amount of dice you wish to roll, and y is the size of the dice you with to roll");
- System.exit(0);
- }
- int num = Integer.parseInt(args[0]);
- int size = Integer.parseInt(args[1]);
- System.out.println("Rolling "+ num + "d" + size);
- List<Integer> list2 = dice.DiceRoll(size,num);
- if (num == 1) {
- System.out.println("Your Rolled a " + list2.get(0));
- }
- else {
- System.out.print("Your Rolled a " + list2.get(0) + " ");
- list2.remove(0);
- System.out.print(list2);
- }
- }
- public static List DiceRoll(int size, int num) {
- List<Integer> list = new ArrayList<Integer>();
- list.add(1);
- while(num > 0) {
- Random generator = new Random();
- int finroll = generator.nextInt(size) + 1;
- num = num - 1;
- list.add(finroll);
- }
- int sum = 0;
- for (int i : list) {
- sum += i;
- }
- list.set(0,sum);
- return (list);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment