nextLine()没有暂停

时间:2012-06-24 07:45:45

标签: java

  

可能重复:
  java.util.Scanner : why my nextLine() in my code not promt?

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”持续下去。它只是跳过并打印“插入下一个数字:”。这是为什么?

0 个答案:

没有答案