本帖最后由 zx0210 于 2015-9-14 00:50 编辑
今天在Eclipse的console上演示的时候,多次输入的时候在输入了第一个字符按下enter之后,输入第二个字符的时候就出现bug了
- <div>import java.util.Scanner;
- public class StudentsTest {
- public static void main(String[] args) {
- Student[] stu = new Student[5];
- System.out.println("学生信息录入开始:");
- for (int x = 0; x < stu.length; x++) {
- @SuppressWarnings("resource")
- Scanner sc = new Scanner(System.in);
- System.out.print("请输入第" + (x + 1) + "个学生的姓名:");
- String name = sc.nextLine();
- System.out.print("请输入第" + (x + 1) + "个学生的年龄:");
- int age = sc.nextInt();
- Student s = new Student(name,age);
- stu[x] = s;
- }
- System.out.println("学生数据录入完毕!");
- System.out.println("开始打印学生数据:");
- System.out.println("\t" + "学生姓名\t\t" + "学生年龄");
- for (int i = 0; i < stu.length; i++) {
- System.out.println("\t" + stu[i].getName() + "\t\t" + stu[i].getAge());
- }
- }
- }
- </div>
复制代码
|
|