020-29133788
    资 讯
    您的位置:首页 >> 资 讯 >> 软件应用 >> 编程开发 >> 正文
    [JAVA]成绩排名之阵列使用

    点击:   发布日期:2013-01-18

    本文来自 www.020fix.com
    [JAVA]成绩排名之阵列使用
    引用:

        import java.io.*;
        public class demo17{  
                public static void main(String args[]) throws Exception
                {  //程式进入点
                        String getbr;
                        BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
                        int i,x,j,k;
                        float score[],inp;
                        int flag;
                        /*****请使用者输入选项**********/
                        System.out.print("请输入学生数:");
                        getbr = br.readLine();
                        x=Integer.parseInt(getbr);//取得学生数
                        score=new float[x]; //定义分数阵列
                        for (i=0;i<x;i=i+1) //利用类似insertion sort的方法来算名次
                        {
                           System.out.print("输入第"+(i+1)+"个分数:");
                           getbr = br.readLine();
                           inp=Float.parseFloat(getbr);//取得学生数
                           flag=0;
                           for (j=x-1;j>0;j=j-1)
                           {
                              if (score[j-1]<inp) score[j]=score[j-1];
                              else
                                {
                                        score[j]=inp;
                                        flag=1;
                                        break;
                                }//else
                           } // for j 做 排序
                           if (flag==0) score[0]=inp;
                           for (k=0;k<x;k=k+1) //利用类似insertion sort的方法来算名次
                           System.out.println("第"+(k+1)+"名="+score[k]);
                        }
                        for (i=0;i<x;i=i+1) //利用类似insertion sort的方法来算名次
                          System.out.println("第"+(i+1)+"名="+score);
                } //main 结束
        }