-3

我想制作一个一维数组,直到用户输入“alldone”,但是我不知道如何制作它。这是我所拥有的,我知道这是错误的。

指令是“设计一个请求和接收学生姓名和每个考试分数的解决方案。使用一维数组来解决这个问题。

程序应该继续接受姓名和分数,直到用户输入一个名字为“alldone”的学生。输入完成后,确定哪个学生的分数最高,并显示该学生的姓名和分数。最后按升序对姓名列表和对应分数进行排序。”

到目前为止的代码:

String name = "";
    String highName = "";
    int highScore = 0;
    while (name != "alldone") {
        System.out.println("Enter name of student");
        name = input.nextLine();
        System.out.println("Enter grade of student.");
        int score = input.nextInt();
        if (name != "alldone" && score > highScore)
            highName = name;
        highScore = score;
        // System.out.println("Enter name"); name = input.nextLine(); }
        // System.out.println(highName + " had the highest score which was "
        // + highScore);
    }

现在我已经做到了

     Scanner in = new Scanner(System.in);
     int size= 1;

     String[] studentNames= new String[size];

     System.out.println("Enter name of student");
     String input = in.nextLine();
     String name = input;

     if (!name.equals("alldone")) {
         for (int i = 0; i < size; i++)
             studentNames[i]= in.nextLine();
      } 
     else return;
     for (int k = 0; k<studentNames.length; k++) {
         System.out.println(studentNames[k] + " "); //so it can display names
4

1 回答 1

1

你应该改用这个:

        if (!name.equals("alldone"))
于 2017-01-24T04:10:14.987 回答