在我的代码中,我如何才能返回到第一行代码。 这样输出将是:
您必须输入介于100和99999之间的值
写出您想发送多少个数据包:(介于100-99999之间)
2
您必须输入100到99999之间的值
写出您想发送多少个数据包:(介于100-99999之间)
200
因此,每次输入错误的数字时,都会显示第一行,直到正确为止。
System.out.println("\n Write how much packets you want to send : (between 100 - 99999)");
int min = 100;
int max = 99999;
int packets = scan.nextInt();
if (packets >= min && packets <= max) {
System.out.println("You have sended : " + packets + " packets");
System.out.println("\n Attack is processing...");
try {
Thread.sleep(5000);
}
catch (InterruptedException ex)
{
}
System.out.println("\n Attack is done");
try {
Thread.sleep(1000);
}
catch (InterruptedException ex)
{
}
}else {
System.out.println("You have to put a value between 100 and 99999");
// Here I want to return to line 1
}
答案 0 :(得分:1)
尝试while
循环。
boolean isRescanRequired = true;
while(isRescanRequired){
// your scanning code goes here
if (packets >= min && packets <= max) {
// your processing and sleep code
isRescanRequired = false;
}
}