iv’e been searching around but it’s hard to find an answer for this specific code. I’m looking to make my if statement search for the delimiter – then use the apply the integers before and after to a variable. E.G. if they inputted 1-50 it would apply 1 to int a and 50 to int b. Here’s the if statement i’m looking to apply it to. It would come from the input variable :
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;
}
Thanks for any help.
You can use StringTokenizer class to parse strings. For ex:
If you do this; a will be 1, b will be 50. I didn’t try this code but it must be like this.