プログラムは感謝(名前)を印刷していません。代わりに、ラインは完全にスキップされてメインメニューに戻ります。誰かが理由を説明できますか?表示されたインデックスに基づいて新しい文字列を作成し、結果を '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 [カウンタ]' '文字列firstName = unprocessed.substring(0、unprocessed.indexOf( '')); ' おそらく役に立ちます。 – marcushobson