#how can i make my code rerun it self till i stop it from cmd

1 messages · Page 1 of 1 (latest)

left anchor
#

Hello im new to java so can someone tell me how can i make my code rerun it self after getting the final result idk what method to use and i dont think (while or for) loops are helpful at that sitiuation
for exp in this code after entering the number and getting the result i want it go back and ask me if i wanna enter new numbers or finish

formal condorBOT
#

<@&987246399047479336> please have a look, thanks.

formal condorBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

There are multiple ways to make your code rerun until you stop it. One common approach is to use a loop, such as a while loop or do-while loop. Here's an example using a while loop:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String userInput;

        do {
            // Your code goes here
            
            System.out.println("Do you want to rerun the code? (yes/no)");
            userInput = scanner.nextLine();
        } while (userInput.equalsIgnoreCase("yes"));
        
        System.out.println("Program stopped.");
    }
}

In this example, the code inside the do block will be executed at least once, and then it will keep running as long as the user enters "yes" when prompted. If the user enters anything other than "yes", the loop will exit and the program will stop.

You can modify this example according to your specific requirements and add your own code inside the do block.

left anchor
#

tried the code but still missing smth

wheat crystal
neat ocean
left anchor
left anchor
neat ocean
left anchor
# left anchor

i tried the do-while loop here but it doesnt give me a chance to put my answer

neat ocean
#

they are the perfect tool for the situation

left anchor
neat ocean
neat ocean
#

point is, a loop is the tool to use

left anchor
neat ocean
left anchor
left anchor
#

thank u for your time sir appreicate the help

pseudo ember
neat ocean