2

可能重复:
java.util.Scanner:为什么我的代码中的 nextLine() 没有提示?

import java.util.Scanner;

class apples {
public static void main(String args[]){
        Scanner npwn = new Scanner(System.in);
        int first,second,answer;
        String op;
        System.out.print("Insert first number: ");
        first = npwn.nextInt();
        System.out.print("Insert Operation ('+', '-', '*', '/')");
        op = npwn.nextLine();
        if (op.equals("+")) {
            System.out.print("Insert next number: ");
            second = npwn.nextInt();
            answer = first + second;
        } 
        else { System.out.print("Insert next number: ");
        second = npwn.nextInt(); 
        answer = first - second;

        }
        System.out.println(answer);
}
}

上面写着“op:nextLine();”;它不会停下来等待“nextLine”的文章。它只是跳过并打印“插入下一个数字:”。为什么是这样?

4

0 回答 0