运行是相邻重复值的序列。编写一个程序,生成一系列随机掷骰子并打印骰子值,只标记最长的一次。该程序应将掷骰子的总数(例如 10)作为输入,然后打印:
1 6 6 3 (2 2 2 2 2) 5 2
我很困惑如何比较每个数字以获得正确的输出。也许使用数组来存储值。任何答案或输入都会有所帮助,谢谢!
import java.util.Random;
import java.util.Scanner;
public class Dice
{
Random generator = new Random();
Scanner keyboard = new Scanner(System.in);
public void DiceCount()
{
int count;
int sides = 6;
int number;
System.out.println("How many die? ");
count = keyboard.nextInt();
for(int i=0; i < count; i++)
{
number = generator.nextInt(sides);
System.out.print(number);
}
}
}