-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
56 lines (40 loc) · 1.41 KB
/
Copy pathMain.java
File metadata and controls
56 lines (40 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.Scanner;
import java.util.SplittableRandom;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<Student> students = new ArrayList<>();
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 4; i++) {
addstudent(students);
}
ArrayList<Student> result= shaixuanstudent(students);
for (int i = 0; i < result.size(); i++) {
System.out.println(result.get(i).getName());
}
for (int i = 0; i < students.size(); i++) {
System.out.println(students.get(i).getName());
}
}
public static void addstudent(ArrayList<Student> students) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入学生名字");
String name = sc.next();
System.out.println("请输入学生年龄:");
int age = sc.nextInt();
Student stu =new Student(age,name);
students.add(stu);
}
public static ArrayList<Student> shaixuanstudent(ArrayList<Student> students) {
ArrayList<Student> result = new ArrayList<Student>();
Student stu = new Student(0,"null");
for (int i = 0; i < students.size(); i++) {
if (students.get(i).getAge() <=18) {
stu= students.remove(i);
i--;
result.add(stu);
}
}
return result;
}
}