1 回答

TA貢獻(xiàn)1744條經(jīng)驗(yàn) 獲得超4個(gè)贊
/** Scanning problems */
class Scanning {
public static void main(String[] args) {
int num;
String txt;
Scanner scanner = new Scanner(System.in);
// Problem: nextLine() will read previous nextInt()
num = scanner.nextInt();
txt = scanner.nextLine();
// solution #1: read full line and convert it to integer
num = Integer.parseInt(scanner.nextLine());
txt = scanner.nextLine();
// solution #2: consume newline left-over
num = scanner.nextInt();
scanner.nextLine();
txt = scanner.nextLine();
}
}
添加回答
舉報(bào)