Ask Question
18 May, 17:44

Write an expression that executes the loop body as long as the user enters a non-negative number. Note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds and report "Program end never reached." The system doesn't print the test case that caused the reported message.

+4
Answers (1)
  1. 18 May, 21:07
    0
    while (Num>=0) {

    System. out. println ("enter a another number");

    Num = in. nextInt ();

    }

    Explanation:

    The complete java code prompting a user to enter a number until a negative number is entered is given below:

    import java. util. Scanner;

    public class num6 {

    public static void main (String [] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("enter a number");

    int Num = in. nextInt ();

    while (Num>=0) {

    System. out. println ("enter a another number");

    Num = in. nextInt ();

    }

    System. out. println ("Done.");

    return;

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write an expression that executes the loop body as long as the user enters a non-negative number. Note: If the submitted code has an ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers