【发布时间】:2017-09-01 12:48:38
【问题描述】:
我已经制作了一个卷号数组,因此如何使用 setter 将用户输入提供给作为卷号的私有属性。
我做了一个学生类的对象,它是一个学生并尝试了这个students.for(int i=0;i<n;i++)
{(setRollno[i](sc.next()))};
但它没有用。
class Students{
private String[] rollno = new String[1000];
private int[] intel = new int[1000];
private int[] type = new int[1000];
private String[] name = new String[1000];
public void setRollno(String[] rollno) {
this.rollno = rollno;
}
public void setName(String[] name) {
this.name = name;
}
public void setIntel(int[] intel) {
this.intel = intel;
}
public void setType(int[] type) {
this.type = type;
}
public String[] getRollno() {
return rollno;
}
public String[] getName() {
return name;
}
public int[] getIntel() {
return intel;
}
public int[] getType() {
return type;
}
}
【问题讨论】:
-
你的意思是
students.setType(students.(? -
1.您不能在像 setRollno[i] 2 这样的方法调用上使用数组 [i]。您必须将该方法传递给字符串数组,而不是字符串
-
我想使用 setter 向 rollno 数组提供用户输入。
-
所以你只想修改你的rollno的一个值?如果不是,请告诉我,我会更新我的答案。
-
你可能想用这个来代替:
students.getRollno()[i] = sc.next();.
标签: java oop private setter getter