Newbie
Newbie

Reputation: 31

How do I manage to return back to a line code?

In my code, how can I manage to return to my first line of code. So that the output would be :

You have to put a value between 100 and 99999

Write how much packets you want to send : (between 100 - 99999)

2

You have to put a value between 100 and 99999

Write how much packets you want to send : (between 100 - 99999)

200

So that each time, the wrong number is entered, the first line will show up until it is correct.

    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
    }

Upvotes: 1

Views: 150

Answers (1)

GirishB
GirishB

Reputation: 144

Try while loop.

boolean isRescanRequired = true;
while(isRescanRequired){
    // your scanning code goes here
    if (packets >= min && packets <= max) {
        // your processing and sleep code
        isRescanRequired = false;
    }
}

Upvotes: 1

Related Questions