Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAVA:如何以整数“结束输入”-1“;_Java_Input_Integer - Fatal编程技术网

JAVA:如何以整数“结束输入”-1“;

JAVA:如何以整数“结束输入”-1“;,java,input,integer,Java,Input,Integer,输入整数“-1”时如何结束此输入 if(op.contains("SENTINEL")){ while(!sc.next.equals("-1")){ String action = sc.next(); int a= sc.nextInt(); int b= sc.nextInt(); int ans=countAns(action, a, b); System.out.println(+ans); }} 当您

输入整数“-1”时如何结束此输入

if(op.contains("SENTINEL")){
while(!sc.next.equals("-1")){
String action = sc.next();                                         
int a= sc.nextInt();
int b= sc.nextInt();
int ans=countAns(action, a, b);
System.out.println(+ans);
}}

当您输入
-1
不需要任何东西时,此循环将结束


但是这部分中有语法错误:
!sc.next.equals(“-1”)
,应该这样写!sc.next().equals(“-1”)

while条件下哪个变量的整数输入,或字符串操作的a或b?整数输入。因此,如果输入-1作为字符串变量action,while循环将中断。