The program when ran, will let theuser roll a pair of dice n-times (i.e. generate a number between 1and 6), where n is a positive integer entered by a user. Theprogram then outputs the pair of numbers rolled by the dice, aswell as the sum of the numbers r

匿名用户 最后更新于 2021-11-29 17:10 计算机类Computing

The program when ran, will let theuser roll a pair of dice n-times (i.e. generate a number between 1and 6), where n is a positive integer entered by a user. Theprogram then outputs the pair of numbers rolled by the dice, aswell as the sum of the numbers rolled by each pair of dice. Thepairs of numbers are stored in a 2-dimensional array, and the sumof each pair are stored in a single-dimensional array. Howeverthere are errors in the program that needs to bechanged. Debug the program in order for it to run as stated inits specification.

import java.util.Scanner; import java.util. Random; public class Finalexam{ public static void main (String() args) { Scanner input = Scanner(System.in); System.out.print("Enter the amount of times a pair of dice will roll: "); int times = keyboard.nextInt(); int[] dicePairs = rollDicepairs(times); System.out.println("The rolled pairs of numbers are:"); printDicePairs(dicePairs); System.out.println("The sum of each pairs of numbers are:"); int[][] dicePairsSums = addDicePairs(dicePairs); printDicePairsSums(dicePairsSums); } public static double[][] rollDicepairs(int times) { int[][] dice = new int[times ][2]; Random die = new Random(); for(int x=0; x

已邀请: