gpt4 book ai didi

java - 输入扫描仪被跳过

转载 作者:行者123 更新时间:2023-12-02 09:27:50 25 4
gpt4 key购买 nike

这段代码实际上在 if 语句中(决定它是讲师还是学生,但两者的问题是相同的,输入名称被跳过)讲师a = new Lecturer();

        System.out.print("Please enter your Lecturer Identification Number, Sir : ");
input.nextLine();
a.setLect_num(input.nextLine());

System.out.print("\nPlease insert your Name, Sir : ");
a.setName(input.nextLine());

System.out.print("\nPlease enter your Age, Sir : ");
a.setAge(input.nextInt());

System.out.print("\nPlese enter the course you are in charge, Sir : ");
input.nextLine();
a.setCourse(input.nextLine());

a.setOccupation("Teacher");
a.introduction();

最佳答案

在代码片段的第 2 行中,您正在收集来自扫描仪的输入并丢弃它:

System.out.print("Please enter your Lecturer Identification Number, Sir : ");
input.nextLine(); // this line is gathering input and discarding it
a.setLect_num(input.nextLine());

关于java - 输入扫描仪被跳过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58211507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com