嘿所有我想要我的代码打印如下:
John Smith,Math,4.0,True
Jessica Snow,Communications,4.0,false
Chris Christopherson,Science,3.2,True
目前它在一行上打印如下: John Smith,Math,4.0,True,Jessica Snow,Communications,4.0,false,Chris Christopherson,Science,3.2,True
如何让它在不同的行上打印?
public static int addStudent(ArrayList students){
Scanner inputStudents = new Scanner(System.in);
System.out.println("Please Enter first name");
String fname = inputStudents.nextLine();
students.add(fname);
System.out.println("Please Enter Last name");
String lname = inputStudents.nextLine();
students.add(lname);
System.out.println("Please enter department of student's major");
String department = inputStudents.nextLine();
students.add(department);
System.out.println("Please Enter GPA");
Double gpa = inputStudents.nextDouble();
students.add(gpa);
System.out.println("Is the student involved in extracurriculars")
(true/false):");
boolean extras = inputStudents.nextBoolean();
students.add(extras);
return 0;
抱歉,我是个白痴,这是我的打印代码:
}
public void print(){
System.out.println(this.fname + " " +this.lname + " " + this.department+ "
" + this.gpa + " "+ this.extras);
}
}
答案 0 :(得分:-1)
在您的函数返回中收集了学生之后,通过for循环迭代ArrayList。在这种情况下,这是一个示例循环:
Type Checker: Expression should produce 9 values, but produces 1 values of
types SQL-Datum in: (for/list (((n s str dex con bhp chp bac attack
(in-query c "select * from players"))) (player n s str dex con bhp chp bac
attack))
此外,将函数设为null,因为除非您计划执行某些操作,否则不必返回0以外的任何内容。
编辑:修复。