送分题最后一个,为什么输出把最高的分数放在最后就不行

        int n;
        n = in.nextInt();
        int[] xuehao = new int[n];
        String[] name = new String[n];
        double[] fenshu = new double[n];

        String zgmz;
        int zgxh;
        int j = 0;
        double a = 0;
        String b = null;
        int c = 0;
        for (int i = 0; i < n; i++) {
            xuehao[i] = in.nextInt();
            name[i] = in.next();
            fenshu[i] = in.nextDouble();

        }
        for (int i = 0; i < n - 1; i++) {
            if (fenshu[i] > fenshu[i + 1]) {
                fenshu[j] = fenshu[i];
                a = fenshu[i];
                b = name[i];
                c = xuehao[i];
            }
        }

        System.out.println("分数最高的是" + b);
        System.out.println(b + "的学号是" + c);
        System.out.println(b + "考了" + (int) a + "分");

4 条评论

  • @ 2019-05-15 21:19:03

    好了

  • @ 2019-05-15 21:18:52
            int n;
            n = in.nextInt();
            int[] xuehao = new int[n];
            String[] name = new String[n];
            double[] fenshu = new double[n];
    
            String zgmz;
            int zgxh;
            int j = 0;
            double a = 0;
            String b = null;
            int c = 0;
            for (int i = 0; i < n; i++) {
                xuehao[i] = in.nextInt();
                name[i] = in.next();
                fenshu[i] = in.nextDouble();
    
            }
            for (int i = 0; i < n - 1; i++) {
                if (fenshu[j] < fenshu[i+1])
                {
                    j = i+1;
                }
            }
    
            ps.println("分数最高的是" + name[j]);
            ps.println(name[j] + "的学号是" + xuehao[j]);
            ps.println(name[j] + "考了" + (int) fenshu[j] + "分");
            
    //      for(int i=n;i > 0;i--) 
    //      {
    //      System.out.println(name[i-1]);
    //      }
            //2019001
    //      int m;
    //      m = in.nextInt();
    //      System.out.println("学号为"+m+"的同学叫做"+name[m-2019001]);
        }
    
    }
    
  • @ 2019-05-15 20:48:01

    你现在第19-26行的代码好像同时干了好几事情,以至于我不太看得懂你的思路。

    我建议你在这几行就干一件事:找到最高分数的下标。其他什么事情都别干。

  • @ 2019-05-15 20:39:52

    排版好乱,请问问别人如何排版

  • 1