学校のプロジェクトに座って、私は本当に混乱しています。 私の最初のnextLine();両方のforループではスキップされます。私はなぜ、私はこの答えは基本的かもしれないが、私は本当にこれを把握することはできません理解するようではありません!最初のnextLine()がスキップされるのはなぜですか?
for (int i = 0; i < antal; i++) {
System.out.println("Name of the customer?");
String name = sc.nextLine();
Kunde.setName(name);
System.out.println("Adress of the customer?");
String adresse = sc.nextLine();
Kunde.setAdress(adresse);
System.out.println("Mail of the customer?");
String mail = sc.nextLine();
Kunde.setMail(mail);
System.out.println("Phone number of the customer?");
int tlf = sc.nextInt();
Kunde.setTlf(tlf);
System.out.println("Postal code of the customer?");
int postalcode = sc.nextInt();
Kunde.setPostalCode(postalcode);
int x = ran.nextInt(100000);
Kunde.setOrderNumber(x);
}
for (int i = 0; i < antal; i++) {
System.out.println("Any specific orderdetails revolving order " + Kunde.getName(i)
+ " If not, press enter");
String details = sc.nextLine();
order.add(details);
}
「スキップする」とはどういう意味ですか?あなたの2番目のforループで、 "特定の注文詳細..."を印刷し、 'Kunde.getName(i)'を呼び出すと、その値は設定されていませんか? 'Kunde'のコードをインクルードするためにあなたの質問を編集する必要があるかもしれません。なぜなら、あなたが一つの値を設定するのは奇妙に思えるかもしれませんが、それではインデックス(' i')で 'get'することです。 'sc.nextLine()'コードはうまく見えるので、 'Kunde'からどのように値を取得しているのかは分かります。 – DaveyDaveDave
「顧客の名前」と「顧客の住所」は、nextLine()メソッドからプロンプトが表示されることなく、同時に印刷されます。 –
これは正しいとは言えません - スキャナの設定方法あなたの投稿を編集することはできますか?あなたは「顧客のメール?」ブロックに期待どおりに機能しますか?あなたのスキャナはどこから読んでいますか?それは標準入力かファイルなのですか? 'String name = sc.nextLine()'の直後の行に 'System.out.println(" Name is: "+ name)'を追加するとどうなりますか? – DaveyDaveDave