我添加了一个for循环,大小为3,它应该扫描3次,但它正在扫描4次。对于4大小,它的扫描6次,可以帮助我。
public class Control {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
List<Student> studs = new ArrayList<Student>();
for (int i = 1;i < 3;i++) { //Here the for loop
System.out.println("Enter age and name :");
Student stu1 = new Student(sc.nextInt(),sc.nextLine());
System.out.println("Enter age and name :");
Student stu2 = new Student(sc.nextInt(),sc.nextLine());
studs.add(stu1);
studs.add(stu2);
Collections.sort(studs,new StudAge());
}
for(Student stud : studs) {
System.out.println(stud);
}
}
}
答案 0 :(得分:1)
SELECT ID, V_ID
FROM
(
SELECT *, ROW_NUMBER() OVER (PARTITION BY ID ORDER BY V_ID DESC) rn
FROM test
) t
WHERE rn = 1;
nextInt不能解释您提交int时按下的回车,因此您必须抓住未使用的回车键