0
所以,我希望sArr在if之后有一个数字,并且每次循环结束时都会递增。我不知道我做错了什么,有人可以解释吗?用于创建具有递增名称的对象的数组
import java.util.*;
public class StudentTest {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
String id, name, gender, address;
Student[] sArr = new Student[4];
int age;
for(int i=0; i>=sArr.length(); i++){
System.out.println("student id.");
id = in.nextLine();
in.nextLine();
System.out.println("Sutdent name.");
name = in.nextLine();
in.nextLine();
System.out.println("Gender.");
gender = in.nextLine();
in.nextLine();
System.out.println("Address.");
address = in.nextLine();
in.nextLine();
System.out.println("Age");
age = in.nextInt();
Student sArr[i] = new Student(id, name, gender, age, address);
s2.display();
}
}
}
此代码给了我这些错误:
--------------------Configuration: <Default>--------------------
C:\StudentTest.java:31: error: ']' expected
Student sArr[i] = new Student(id, name, gender, age, address);
^
C:\Users\Bart\Desktop\Bart Kosinski_2886295_Assignment01\StudentTest.java:31: error: illegal start of expression
Student sArr[i] = new Student(id, name, gender, age, address);
^
2 errors
Process completed.