[英]Scanner not asking input of string
在下面的代碼中:
secondI = scan.nextInt();
System.out.println("double");
secondD = scan.nextDouble();
System.out.println("string");
secondS = scan.nextLine();
輸入雙精度值后,它將跳過字符串輸入部分。 我怎樣才能解決這個問題?
secondI = scan.nextInt();
System.out.println("double");
secondD = scan.nextDouble();
scan.nextLine();
System.out.println("string");
secondS = scan.nextLine();
您需要有一個額外的nextline語句 ,該語句將占用您為double值輸入的該行的其余部分。
采用
secondS = scan.next();
代替
secondS = scan.nextLine();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.