日期:2014-05-20 浏览次数:20768 次
import javax.swing.JOptionPane; public class Tangjifengshu { public static void main(String[] s) { int numberstudents=0; int[] scores; int i=0; int best=0; char grade='0'; String numberstudentsString=JOptionPane.showInputDialog(null, "Please enter number of students:","软件班级", JOptionPane.QUESTION_MESSAGE); numberstudents=Integer.parseInt(numberstudentsString); scores=new int[numberstudents]; for( i=0;i <scores.length;i++) { String scoreString=JOptionPane.showInputDialog(null,"Please enter a score","软件班级",JOptionPane.QUESTION_MESSAGE); scores[i]=Integer.parseInt(scoreString); if(scores[i]>best) best=scores[i]; } String output=" "; int []count; count =new int[5]; for( i=0;i <scores.length;i++) { if(scores[i]>=best-10){ grade='A'; count[0]++; } else if(scores[i]>=best-20){ grade='B'; count[1]++; } else if(scores[i]>=best-30){ grade='C'; count[2]++; } else if(scores[i]>=best-40){ grade='D'; count[3]++; } else{ grade='E'; count[4]++; } output +="Studets "+(i+1)+" score is "+scores[i]+" and grade is "+grade+ "\n"; } char c='A'; for (int j = 0; j < count.length; j++) { output+="\n"+(c++)+": "+count[j]; } JOptionPane.showMessageDialog(null,output,"软件班级", JOptionPane.INFORMATION_MESSAGE); } }