我正在尝试使用Java中的Scanner类扫描负数.
我有这个输入文件:
1
-1,2,3
我的代码如下:
Scanner input = new Scanner(new File("data/input.txt"));
int i = input.nextInt();
input.useDelimiter(",|\\s*"); //for future use
int a = input.nextInt();
System.out.println(i);
System.out.println(a);
Run Code Online (Sandbox Code Playgroud)
我的预期输出应该是
1
-1
相反,我得到一个错误(类型不匹配).
当我做
String a = input.next();
Run Code Online (Sandbox Code Playgroud)
代替
int a = input.nextInt();
Run Code Online (Sandbox Code Playgroud)
我不再得到错误而是得到了
1
-
我这样做:
clear();
coinRefundComplete.Visible = true;
state = 0;
System.Threading.Thread.Sleep(4000);
clear();
greeting.Visible = true;
rate.Visible = true;
refundTicket.Visible = true;
currentTime.Visible = true;
Run Code Online (Sandbox Code Playgroud)
我希望coinRefundCompleteText(它是一个标签)出现4秒钟,然后通过我用clear()定义的方法清除,然后发生其他一些事情.相反,在我用第一个clear()清除我的表单后,我的表单空白4秒,然后正确完成.