碳酸氢铵显什么性:[求助]JAVA编程

来源:百度文库 编辑:高考问答 时间:2024/03/29 08:13:32
要求任意名学生按照A、B、C、D等级对学生食堂的饭菜质量进行评估,将反馈结果放到一个整数数组中,并总结调查的结果(统计四个等级各有多少票,并用图形表示出来)
import javax.swing.*;
public class bo
{
public static void main(String args[])
{
String str;
int frequency[]=new int[11];
int xs;
str=JOptionPane.showInputDialog("请输入投票学生的人数:");
xs=Integer.parseInt(str);
int responses[]=new int[xs];

for(int i=1;i<=xs;i++)
{
str=JOptionPane.showInputDialog("请输入投票等级(A,B,C,D):");
responses[i]=Integer.parseInt(str);}
for(int answer=0;answer<responses.length;answer++)
++frequency[responses[answer]];

String output="Rating\tFrequency\n";

for(int rating=1;rating<frequency.length;rating++)
output+=rating+"\t"+frequency[rating]+"\n";

JTextArea outputArea=new JTextArea();
outputArea.setText(output);

JOptionPane.showMessageDialog(null,outputArea,"Student Poll Program",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);

}
}不晓得出了什么错 能帮我调试下吗

import javax.swing.*;
class bo
{
public static void main(String args[])
{
String str;
int frequency[]=new int[11];
int xs;
str=JOptionPane.showInputDialog("请输入投票学生的人数:");
xs=Integer.parseInt(str);
int responses[];
responses=new int[xs];
for(int i=1;i<=xs;i++)
{str=JOptionPane.showInputDialog("请输入投票等级(A,B,C,D):");
responses[i-1]=Integer.parseInt(str);}
for(int answer=0;answer<responses.length;answer++)
++frequency[responses[answer]];

String output="Rating\tFrequency\n";

for(int rating=1;rating<frequency.length;rating++)
output+=rating+"\t"+frequency[rating]+"\n";

JTextArea outputArea=new JTextArea();
outputArea.setText(output);

JOptionPane.showMessageDialog(null,outputArea,"Student Poll Program",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);

}
}