제 do-while 루프가 작동하지 않는 동안 저는 솔직히 잘 모릅니다. 프로그램을 실행할 때마다 그냥 건너 뛰고 답장을 요구하지 않고 계속 진행합니다.Java Do-while 루프가 작동하지 않습니까?
import java.util.*;
public class CourseApp {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
ArrayList <Course> courseList = new ArrayList<Course>();
String reply;
//boolean boolVal = true;
do {
System.out.print("Enter new course number: ");
String tempCourseNum = s.nextLine();
System.out.print("Enter course name: ");
String tempCourseName = s.nextLine();
System.out.print("Enter instructor's last name: ");
String tempLastName = s.nextLine();
System.out.print("Enter instructor's first name: ");
String tempFirstName = s.nextLine();
System.out.print("Enter instructor's username: ");
String tempUsername = s.nextLine();
//new Instructor(tempLastName, tempFirstName, tempUsername);
Instructor tempInstruc = new Instructor(tempLastName, tempFirstName, tempUsername);
System.out.print("Enter textbook title: ");
String tempTitle = s.nextLine();
System.out.print("Enter textbook author: ");
String tempAuthor = s.nextLine();
System.out.print("Enter textbook price (no $ sign): ");
double tempPrice = s.nextDouble();
//new TextBook(tempTitle, tempAuthor, tempPrice);
TextBook tempText = new TextBook(tempTitle, tempAuthor, tempPrice);
courseList.add(new Course(tempCourseNum, tempCourseName, tempInstruc, tempText));
System.out.print("\nEnter another course? (y/n): ");
reply = s.nextLine();
} while (reply.equalsIgnoreCase("Y"));
for (int i =0; i < courseList.size(); i++) {
System.out.println("\n\tCourse #" + (i+1)+":");
System.out.println(courseList.get(i));
}
}
}
사람이 문제가 그
당신은이 할 일에 모든 루프 동안 안타 것을 확신? –
아니, 답장 = s.nextLine()을 건너 뛰고있는 것 같습니다. 아무 것도 입력 할 기회조차주지 못하기 때문입니다. 나는 이것이 왜 이렇게하고 있는지 전혀 모른다. – pittcrew