/** This is a simple dice rolling program. It is designed to simulate the rolling of 10 sided dice. The program takes in two numbers from the user, the number of dice rolled (r), and the number of dice kept (k). The program then generates r sets of random integers from 1-10. If a roll is equal to 10, it is rerolled and 10 is added to the new value (called exploding, in game terms). The r numbers are then arragned highest to lowest, and k of the highest are kept. These k numbers are added and printed to the screen as the output, along with other data to make it more user-friendly. created by Colin Ahern, May 2007 */ import java.util.Random; import java.util.*; class roll{ public static void main(String[]args){ Scanner sc = new Scanner(system.in); Random rand = new Random(45); int[] dice; int r,k,total,temp=-1; While(temp<=0){ //Determines number of "dice" to be rolled System.out.print("Enter the number of dice to be rolled: "); if(sc.hasNextInt()) temp=sc.nextInt(); } r=temp; temp=-1; while(temp<=0){ //Determines number of "dice" to be kept System.out.print("Please enter the number of dice to be kept: "); if(sc.hasNextint()) temp=sc.nextInt(); if(temp>r){ //Checks if kept is greater than rolled temp=-1; System.out.println("Dice kept greater than dice rolled. "+r+" dice will be rolled."); } } k=temp; dice = new Int[r]; for(int i=0;imax){ //If the highest value is not at the start of the array, move it there temp=roll[count]; roll[count]=roll[count2]; roll[count2]=temp; } } count++ } } }