나는 서점을위한 프로그램을 작성하여 비즈니스를 예측할 수있는 과제를 가지고 있습니다. 이를 위해 사용자는 도서 코드, 도서 단가, 현재 도서 수, 장래 학급 등록 등과 같은 모든 종류의 입력을 요구합니다. 그러나, 나는 사용자가 장래 등록을위한 부적당 한 입장이있을 때, 사용자가 무효 입장을 입력 할 때 문제점을 직면하고있다, 프로그램은 동일한 질문을 다시 요구하기 대신에 처음부터 질문을 묻는 시작한다.자바에서 스캐너 사용 관련 문제
누구든지 내가 뭘 잘못하고 있는지 알아낼 수 있습니까? 여기 내 코드가있다.
미리 감사드립니다. 당신은 루프에서 질문을하고
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Welcome to College Store Sale Class.");
System.out.println("Please enter all the info below as asked.");
System.out.println("Write either 'Continue' or 'Exit' to continue or exit program respectively. ");
double bookCost;
int bookAvailable;
String ending = sc.next();
int prosepectiveEnrollment;
String rOrO;
String nOrU;
while(!ending.equals("exit")){
System.out.print("Please enter the cost of book ($>=0). ");
bookCost = sc.nextDouble();
if(bookCost >= 0){
System.out.print("Please enter the number of books available (n>=0). ");
bookAvailable = sc.nextInt();
if(bookAvailable >= 0){
System.out.print("Please enter prospective class enrollement > 0: ");
prosepectiveEnrollment = sc.nextInt();
if(prosepectiveEnrollment > 0){
System.out.print("Is the book Required or Optional (ignoreCase)? ");
rOrO = sc.next();
if((rOrO.equalsIgnoreCase("Required") || rOrO.equalsIgnoreCase("Optional"))){
System.out.print("Is the book New or Used? Enter in 'N' or 'U' format. ");
nOrU = sc.next();
if((nOrU.equalsIgnoreCase("New") || nOrU.equalsIgnoreCase("Used"))){
System.out.println("Thanks for correct info, below is your result");
}
else{
System.out.println("(E) Please enter either 'New' or 'Used'. ");
}
}
else{
System.out.println("(D) Please enter either 'Required' or 'Optional'. ");
}
}
else{
System.out.println("(C) Number of prospective class enrollement must be > 0.");
}
}
else{
System.out.println("(B) Number of books should be >= 0.");
}
}
else{
System.out.println("(A) Cost should be >= 0. ");
}
}
if(ending.equalsIgnoreCase("exit"))
System.out.println("See ya later..!! Bbyee..");
sc.close();
}
'내가 작동 있으면 알려 주시기 수 있습니다 사용자가 잘못된 항목을 입력 할 때 직면하는 문제, 내가 뭘 잘못했는지 알 수있는 사람이 누구든지, 우리가 그 문제를 알지 못하면 무엇이 잘못되었는지 말할 수 없습니다. – SomeJavaGuy
사용자가 'int'대신 "A"를 입력하면 main에서 벗어난 예외가 발생해야합니다. 그게 니가 본거야? – Scovetta
@Scovetta 아니요, '도서 비용 ($> = 0)을 입력하십시오. ** 1 **' '사용 가능한 책 수를 입력하십시오 (n> = 0). ** 1 **' '예상되는 학급 등록을 입력하십시오.> 0 : ** - 1 **' '_ (C) 예정 학급 등록 수> 0_' '도서 비용을 입력하십시오 ($> = 0). ' 반복되는 패턴이 여기에 표시됩니까? 사용자가 예상 등록에 대해 잘못된 입력을 한 경우 동일한 질문을하기보다는 책의 비용을 다시 입력해야하는지 묻습니다. – Aayush