java循环输入结构体数组
时间: 2023-11-11 10:59:00 浏览: 99
可以使用for循环和Scanner类来实现循环输入结构体数组,具体代码如下:
```
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt(); // 数组长度
Student[] students = new Student[n]; // 结构体数组
for (int i = 0; i < n; i++) {
students[i] = new Student();
students[i].name = scanner.next();
students[i].age = scanner.nextInt();
students[i].score = scanner.nextDouble();
}
for (int i = 0; i < n; i++) {
System.out.println(students[i].name + " " + students[i].age + " " + students[i].score);
}
}
}
class Student {
String name;
int age;
double score;
}
```
阅读全文