if (yes.equalsIgnoreCase("no")){
if (a.equalsIgnoreCase(answer) && input.equalsIgnoreCase("instant")){
Thread.sleep(1);
}
else if (a.equalsIgnoreCase(answer) && input.equalsIgnoreCase("generate")){
Thread.sleep(randomInt);
}
else if (a.equalsIgnoreCase(answer) && !input.equalsIgnoreCase("generate") && !input.equalsIgnoreCase("instant")){
int x =Integer.parseInt(input);
x = x*60000;
Thread.sleep(x);
}
else if (a.equals("quit" )){
System.exit(0);
}
else if (a.equals("Quit")){
System.exit(0);
}
else if (a.equals("")){
}
else{
JOptionPane.showMessageDialog(null,"Please check the answer then try again ");
i = i-2;
}
感谢您的帮助。
答案 0 :(得分:2)
看看String.split()
。它会返回String[]
,您稍后可以使用Integer.valueOf()
例如:
String s = "1-50";
System.out.println(Arrays.toString(s.split("-")));
wil print [1,50]
答案 1 :(得分:1)
您可以使用StringTokenizer类来解析字符串。例如:
StringTokenizer tokens = new StringTokenizer("1-50","-");
int a = Integer.parseInt(tokens.nextToken());
int b = Integer.parseInt(tokens.nextToken());
如果你这样做; a将是1,b将是50.我没有尝试这个代码,但它必须是这样的。