0
이 프로그램이 가장 긴 행보를 표시하는 방법을 알아낼 수 있습니까? 두 개의 주사위를 굴리고 각 주사위의 합계를 기록합니다. 이제는 가장 긴 행에서 가장 길었던 주사위가 14999966에서 시작된 8 개의 7이 뛰었습니다. "RollingDice Java 프로그램 최장수 행진
import java.util.Scanner;
import java.text.DecimalFormat;
public class RollThoseDice {
/* Author: Name
* Assignment: Third Program
*/
public static void main(String[] args) {
Scanner kbd = new Scanner(System.in);
int timesRolled, randomOutSum;
DecimalFormat df = new DecimalFormat ("#.###");
System.out.println("Name: "
+ "\nAssignment: Third Program"
+"\nExtra Credit: Percentage is displayed in three decimal places");
int[] d = new int[13];
for (int i = 2; i < 13; i++) d[i] = 0;
int N=0;
boolean againA = true;
while(againA) {
try{
System.out.print("\nHow Many Rolls? ");
N =kbd.nextInt();
againA = false;
} catch(Exception e) {
System.out.println("Invalid Input");
kbd.next();
}
}
for (int k = 0; k < N; k++) {
int diceOut1 = (int) (Math.random()*6+1);
int diceOut2 = (int) (Math.random()*6+1);
int diceSum = diceOut1 + diceOut2;
d[diceSum]++;
}
for (int i = 2; i < 13; i++)
System.out.println("Total " + i + " happened "
+ df.format((double) (d[(int) i]/(double) N) * 100)
+ "% of the time.");
}
}
지금까지 시도한 것을 보여줄 수 있습니까? – doelleri
[기본 Java 주사위 프로그램 - 가장 긴 행보 찾기에 문제가 있습니다.] (http://stackoverflow.com/questions/28354928/basic-java-dice-program-trouble-finding-longest-streak)와 중복되는 것으로 보입니다. – doelleri