프로그램이 감사 (이름)를 인쇄하지 않습니다. 대신 줄이 완전히 건너 뛰고 주 메뉴로 돌아갑니다. 누군가 이유를 설명해 주시겠습니까? 그것은 표시된 인덱스를 기반으로 새로운 문자열을 생성하고 'firstName'에 결과를 저장 한 다음 'Thanks (name)!'로 출력해야합니다.왜 내 println이 작동하지 않습니까?
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String[] custInfo = new String[20];
String MANAGERID = "ABC 132";
String userInput;
String cust = "Customer";
String pts = "Print to screen";
String exit = "Exit";
int counter = 0;
int full = 21;
boolean cont = true;
while(cont) {
System.out.println("Enter the word \"Customer\" if you are a customer or your ID if you are a manager.");
userInput = in.nextLine();
if (userInput.equalsIgnoreCase(exit)) {
System.out.println("Bye!");
System.exit(0);
}
try {
if (userInput.equalsIgnoreCase(cust)) {
System.out.println("Hello, please enter your name and DoB in name MM/DD/YYYY format.");
custInfo[counter] = in.nextLine();
String firstName=custInfo[counter].substring(0,(' '));
System.out.println("Thanks "+firstName+"!");
counter++;
}
if (counter==full) {
System.out.println("Sorry, no more customers.");
}
} catch(IndexOutOfBoundsException e) {
}
}
}
하위 문자열 (0, (''))은 어떻게해야하나요? –
try/catch를 제거하거나 잡히는 오류 메시지를 인쇄하십시오. 그러면 문제가 보일 것입니다. – JBC
'문자열 처리되지 않음 = custInfo [counter]' '문자열 firstName = unprocessed.substring (0, 처리되지 않은 .indexOf ('')); ' 도움이 될 것입니다. – marcushobson