後的方法我不能夠使用nextInt
method.This後使用nextLine
方法在下面給出的說明....使用nextLine()使用nextInt()方法
音符黑客排名:(如果您使用方法nextInt()
後立即使用方法,請回想一下,nextInt()
讀取整數標記;因此,該整數輸入行的最後一個換行符仍在輸入緩衝區中排隊,並且下一個nextLine()
將讀取整數的其餘部分行(空) nextLine方法沒有被滑過,但它是空的。 代碼:
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int i = scan.nextInt();
double d=scan.nextDouble();
String s=scan.nextLine();
// Write your code here.
System.out.println("String: " + s);
System.out.println("Double: " + d);
System.out.println("Int: " + i);
}
}
輸出: 字符串: 雙:3.1415 INT:42
你能否向我們展示一些代碼? –
向我們顯示代碼和您遇到錯誤的位置。所以我們可以幫你解決它 – sForSujit