1 6 1) Trace the game. 2) Just give the answer. Please enter 1 or 2 Please enter the dice face number that you would like to be repeated. Please enter the number of times that you would like 6 to appear in a row. 3 You got a 1 Number of times in a row so far is 0 Number of throws is 1 You got a 6 Number of times in a row so far is 1 Number of throws is 2 You got a 2 Number of times in a row so far is 0 Number of throws is 3
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
I need help fixing a java program that includes an if and else statement where it shows the process and the other just prints the number of throws it took:
Version 1 section
Java code:
import java.util.Scanner;
public class Part_2 {
public static void main(String[] args) {
int diceFaceNumber, numTimes, numThrows;
System.out.print(" This game throws a dice until a particular dice face number");
System.out.print(" appears in a row a certain number of times.");
System.out.print("Please enter the version you want:");
System.out.print(" 1) Trace the game.");
System.out.print(" 2) Just give the answer");
System.out.print("Please enter 1 or 2");
if (input == 1);
Scanner input = new Scanner(System.in);
System.out.print("Please enter the die face number you would like to be repeated. ");
diceFaceNumber = input.nextInt();
System.out.print("How many times you want that die face number to appear in a row? : ");
numTimes = input.nextInt();
numThrows = computeNumThrows(diceFaceNumber, numTimes);
printOutput(diceFaceNumber, numTimes, numThrows);
}
private static int computeNumThrows(int diceFaceNumber, int numTimes) {
int numThrows = 0;
int count = 0;
while (count < numTimes) {
int die = (int)(Math.random() * 6) + 1;
numThrows++;
if (die == diceFaceNumber)
count++;
else
count = 0;
}
return numThrows;
}
private static void printOutput(int diceFaceNumber, int numTimes, int numThrows) {
System.out.println("It took " + numThrows + " throws to get " + numTimes + " " + diceFaceNumber + "'s in a row.");
System.out.println(" Would you like to play the game again? ");
System.out.println(" Please enter (yes/no)");
}
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images