public class Main
{
public static void main(String[] args)/*时代Java - nowjava.com 提 供*/
{
// student response array (more typically, input at run time)
int[] responses = {1, 3, 5, 4, 3, 5, 2, 1, 3, 3, 3, 4, 3, 3, 3,
2, 3, 3, 2, 14};
int[] frequency = new int[6]; // array of frequency counters
for (int answer = 0; answer < responses.length; answer++)
{
try
{
++frequency[responses[answer]];
}
catch (ArrayIndexOutOfBoundsException e)
{/*时 代 Java 公 众 号 - nowjava.com 提 供*/
System.out.println(e); // invokes toString method
System.out.printf(" responses[%d] = %d%n%n",
answer, responses[answer]);
}
}
System.out.printf("%s%10s%n", "Rating", "Frequency");
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。