编写程序,提示用户输入学生的数量及每个学生的名字和得分,而后显示最高分的学生?不用数组和方法怎么做到?import javax.swing.JOptionPane;
public class j {
public static void main(String[] args) {
String a = JOptionPane.showInputDialog(null,"请输入学生的数量");
int d = Integer.parseInt(a);
for(int i = 1; i <= d; i++){
String k = JOptionPane.showInputDialog(null,"请输入第"+i+"位学生的成绩");
//下面我不知道怎么写了。
}

}}

解决方案 »

  1.   

    public static void main(String[] args)
      {
        String a = JOptionPane.showInputDialog(null,"请输入学生的数量");
        int d = Integer.parseInt(a);
        int max=Integer.MIN_VALUE;
        int maxIndex =-1;
        int temp=0;
        for(int i = 1; i <= d; i++){
        String k = JOptionPane.showInputDialog(null,"请输入第"+i+"位学生的成绩"); 
          temp =Integer.valueOf(k);
          if(temp>max){
            max=temp;
            maxIndex=i;
          }
        }
        JOptionPane.showMessageDialog(null, "第"+ maxIndex+"位学生的成绩最高,成绩是:"+max);
      }
      

  2.   

    难道说用结构体,可java貌似没有啊
      

  3.   

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */package exp1;/**
     *
     * @author szhu5
     */
    import javax.swing.JOptionPane;
    public class j {
    public   static   void   main(String[]   args)
        {
            String a=JOptionPane.showInputDialog(null, "请输入学生的数量 ");
            int d=Integer.parseInt(a);
            int max=Integer.MIN_VALUE;
            int maxIndex=-1;
            int temp=0;
            for(int i=1;i<=d;i++)
                {
                    String k=JOptionPane.showInputDialog(null, "请输入第 "+i+ "位学生的成绩 ");
                    String f=JOptionPane.showInputDialog(null, "请输入第 "+i+ "位学生的姓名");
                    temp   =Integer.valueOf(k);
                            if(temp> max)
                                {
                                    max=temp;
                                    maxIndex=i;
                                }
                }
            JOptionPane.showMessageDialog(null,"第 "+maxIndex+ "位学生的成绩最高,成绩是:"+max);
        }
    }
      

  4.   

    1楼正解。要显示名字再设置个string记录一下不就行了
      

  5.   

    盗取了1楼的劳动果实   
    public static void main(String[] args) {
    String a = JOptionPane.showInputDialog(null, "请输入学生的数量 ");
    int d = Integer.parseInt(a);
    int max = Integer.MIN_VALUE;
    int maxIndex = -1;
    String maxName = "";
    int temp = 0;
    for (int i = 1; i <= d; i++) {
    String name = JOptionPane.showInputDialog(null, "请输入第 " + i
    + "位学生的名字 ");
    String k = JOptionPane.showInputDialog(null, "请输入第 " + i
    + "位学生的成绩 ");
    temp = Integer.valueOf(k);
    if (temp > max) {
    max = temp;
    maxIndex = i;
    maxName = name;
    }
    }
    JOptionPane.showMessageDialog(null, "第 " + maxIndex + "位学生("+maxName+")的成绩最高,成绩是: "
    + max);
    }有名字的加上数字校验就可以了
      

  6.   


    import java.util.Scanner;
    public class showSname { /**
     * @param args
     */
    public static void main(String[] args) {
    Scanner input=new Scanner(System.in);
    System.out.println("请输入学生数量:");
    int num=input.nextInt();
    String maxName="";
    float maxScore=0;
    for(int i=0;i<num;i++)
    {
    System.out.println("\n请输入第个"+(i+1)+"学生的姓名:");
    String sName=input.next();
    System.out.print("成绩:");
    float sScore=input.nextFloat();
    if(maxScore<sScore)
    {
    maxScore=sScore;
    maxName=sName;
    }
    }
             System.out.println("\n最高分的学生姓名为:"+maxName+",成绩为:"+maxScore);    
    }}
    运行结果:请输入学生数量:
    3请输入第个1学生的姓名:
    张三
    成绩:65请输入第个2学生的姓名:
    李四
    成绩:56请输入第个3学生的姓名:
    王五
    成绩:95最高分的学生姓名为:王五,成绩为:95.0