• Register
1 vote
168 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

Please log in or register to answer this question.

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 109 views
109 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, 2020 maddi86 5.4k points
0 votes
1 answer 17 views
17 views
Problem: Hi there! I am confused in while loops and I need to write a program in which a value is taken as input from the user. If the value is less than 0, the program should increment it by 5 as long as the value remains less than 0. As the value becomes greater than or equal to 0, it should print the number of times the value has been incremented and the final value. Any help??
asked Jan 21 Code Learner 5.7k points
0 votes
1 answer 85 views
85 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, 2020 maddi86 5.4k points
0 votes
1 answer 39 views
39 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, 2020 maddi86 5.4k points
0 votes
1 answer 188 views
188 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, 2020 maddi86 5.4k points
0 votes
2 answers 124 views
124 views
I'm new in java programming, I know how to find out the largest or smallest number from an array. But I'm facing problem when I'm trying to find out smallest staring in 3 string. Please help me write a method min that has three string parameters and returns the smallest.
asked May 2, 2020 samhaz 5k points
0 votes
1 answer 129 views
129 views
Problem: Write an expression whose value is the str that consists of the third to last character of the str associated with s I tried s[2:] didn't work. Can you please guide me with right solution?
asked Feb 19, 2020 maddi86 5.4k points
0 votes
1 answer 15 views
15 views
Problem: Hello programmers! I am a beginner and I have got an assginement in which I have to write a program in Java that will take a number from user as input and will check whether the user entered an even number or an odd number. The program is to be written in ... and I have no idea how to check if a number is even or odd using a program. Any help from you would be much appreciated. Thanks
asked Nov 27, 2020 Code Learner 5.7k points
0 votes
1 answer 255 views
255 views
Problem : Write an expression that prints "special number" if specialnum is -99, 0, or 44.
asked Jan 14, 2020 alecxe 7.5k points