How do I change the program so that it comes out of the while loop in case the entered value is the number Zero or negative? And | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do I change the program so that it comes out of the while loop in case the entered value is the number Zero or negative? And

Hi friends, I wrote this program using java but .. 1- How do I change the program so that it comes out of the while loop in case the entered value is the number Zero or negative? 2- When I change the type of the sum and number of the variables to be of type float, not .double, I'm getting errors in the code Please help me because I want to change the type of two variables without errors 3- Exactly what happens when we use the for command once and then the while-do command again instead of while, I have seen changes, but I could not define them because I want to write notes and learn that. Please write notes about the change that is happening Knowing the code is correct, but there is a problem with Solo Learn, please help me by using another code editor. It is preferred with writing comments on the code for explanation thank you https://code.sololearn.com/c8wEgCna7SO5

20th Nov 2020, 8:15 AM
STOP
STOP - avatar
6 Answers
+ 1
Use while(number>0). Also you have an extra '}' at the end. Remove one.
20th Nov 2020, 8:24 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
@CarrieForle Well, thank you for answering the first question. There are two other questions. Can you answer me? Thank you again Also, I want to ask you can you help me write comments on the code to clarify what we did in the code
20th Nov 2020, 8:30 AM
STOP
STOP - avatar
0
If you have any other question, you can put them on the Q&A section like you did to this one.
20th Nov 2020, 8:32 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
@CarrieForle can you help me write comments on the code to clarify what we did in the code ?? i mean the code I post
20th Nov 2020, 8:35 AM
STOP
STOP - avatar
0
STOP You first get a double value with scanner, and assign it to number. Then you declare a sum with double type and initialized to 0. You make a loop with condition (number != 0). The loop will begin and continue if the condition remains true. You add number to sum. And you ask for another double input. The input will be added to sum until (number != 0) is false. Then you print it.
20th Nov 2020, 8:42 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
@CarrieForle Write comments below the corresponding line of code, please not like this
20th Nov 2020, 9:03 AM
STOP
STOP - avatar