public class trothBrthdays {
public static void main ( String args [] ) {
Random day = new Random();
int days[] = new int[366];
int smallest = 0;
int largest = 885000;
for (int i = 1; i <= 885000; i++)
{
int persons = day.nextInt(365) + 1;
days[persons] += 1;
}
for (int a = 1; a <= 365; a++)
{
System.out.printf ( " \nDay %d: %d ", a, days[a]);
}
程序在这里找到生日最多的日子
for (int b = 0; b < days.length;)
{
if(days[b] > smallest)
{
largest = days[b];
System.out.printf ( "\nLargest: %d ", days[b]);
}
}
程序在这里找到生日最少的一天
for (int c = 0; c > days.length;)
{
if (days[c] < largest)
{
smallest = days[c];
System.out.printf ( "\nSmallest: %d ", days[c]);
}
}
}
}
问题是当程序找到最大数字时,它会无限循环最大数字,我不知道为什么。我仍然是一个初学者程序,并且希望对如何格式化和键入这个程序提出建设性的批评。