• Register
1 vote
111 views

Problem:

Can anyone provide me an expression that executes the loop body as long as the user enters a non-negative number.

Thanks in advance.

10 7 2
6,060 points

1 Answer

1 vote
 
Best answer

Answer :

The program that executes the loop body as long as the user enters a non-negative number is:

import java.util.Scanner;

public class NonNegativeLooper

     public static void main (String [] args)

    

          Scanner scnr = new Scanner(System.in);

          //initialize the userNum with 8

          int userNum = 8;

          //Repeat the loop until the userNum is not negative

          while (userNum>=0)

         

              System.out.println(Body);

              //Prompt the user to enter the userNum again

              userNum = scnr.nextInt();

         

          System.out.println(Done);

          return;

Hope this helps you the most.

Happy coding

11 6 4
34,950 points

Related questions

0 votes
1 answer 73 views
73 views
Solutions: I am new in programming and my logic is not good, can anyone give the right solution? Write an expression that evaluates to true if and only if the C-string s equals the C-string "end"?
asked Feb 14 maddi86 5.4k points
0 votes
1 answer 57 views
57 views
Problem: Can anyone help it was actually asked in exam as following and I need to know whether my answer was right or not? Write an expression that whose value is the fifth character of the String name?
asked Feb 24 maddi86 5.4k points
0 votes
1 answer 18 views
18 views
Problem: I am new to programming, I need help, can anyone help me? Write an expression that evaluates to True if and only if s refers to the str "end"?
asked Feb 18 maddi86 5.4k points
0 votes
1 answer 145 views
145 views
Problem: I am new in programming and stuck in a query, can anyone guide me? Write an expression that evaluates to True if the str associated with s starts with "p"?
asked Feb 17 maddi86 5.4k points