Java排序数组(字符串,双精度数和变量)

时间:2016-07-04 09:47:30

标签: java

我必须使用以下机制创建类SorterDemo

sortDouble - sort array of double variables.

sortString - sort given String value in alphabetical manner.

sortStudent - sort array of Student objects based on marks.

我创建了双变量数组,在main方法中声明了一个String变量以及Student对象数组。我需要显示每个数组的输出,这是由main方法中的三个排序方法产生的。 我收到以下错误:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: The field Student.rollNo is not visible The field Student.name is not visible The field Student.marks is not visible The method nextdouble() is undefined for the type Scanner The method nextdouble() is undefined for the type Scanner Cannot make a static reference to the non-static method sortDouble(double[]) from the type SorterDemo

还需要帮助分类学生分数。

2 个答案:

答案 0 :(得分:0)

Student班级中,rollNo是私有变量,因此您无法直接访问它:stud[i].rollNo。而是在Student类中为此创建一个setter,如下所示:

public void setRollNo(int rollNo) {
  this.rollNo = rollNo;
}

并将上述代码更改为:stud[i].setRollNo(s.nextInt());。对namemarks执行相同操作。

这样可行。 s.nextdouble();也应为s.nextDouble();

答案 1 :(得分:-1)

nextdouble()更改为nextDouble()并声明rollNonamemarks

示例:

public int rollNo 
public String name;
public double marks;
相关问题