What are the differences between a while loop and a do-while loop? Convert the following while loop into a do-while loop:
Scanner input= new Scanner(System.in);
int sum = 0;
System.out.println("Enter an integer " +
"(the input ends if it is 0)");
int number = input.nextInt();
while (number != 0) {
sum += number;
System.out.println("Enter an integer " +
"(the input ends if it is 0)");
number = input.nextlnt();
}
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
Additional Engineering Textbook Solutions
Java How To Program (Early Objects)
Absolute Java (6th Edition)
Starting Out With Visual Basic (7th Edition)
Database Concepts (8th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- Convert the following while loop into for loop : int x =0; while(x <=10) { System.out.println("X : " + x); x+=2; } note : a java codearrow_forwardWhat are the differences between a while loop and a do-while loop? Convert the following while loop into a do-while loop. int sum = 0;int number;cin >> number; while (number != 0) {sum += number; cin >> number; }arrow_forwardConvert the following for loop into do-while loop : for(int c =11; c>=0; c-=2) System.out.println("Count: " + c);arrow_forward
- Examine the following for loops and determine the value of ires at the end of each of the loops, and also the number of times each loop executes. (a) ires = 0; for index = -11:11 ires = ires + 1; end ires = number of times (b) ires = 0; for index = 10:-2:1 if index == 6 continue; end ires = ires + index; end ires = number of times ires = 0; for index = 10:-2:1 if index == 6 (c) break; end ires = ires + index: end ires = number of times (d) ires = 0; for indexl = 10:-2:1 for index2 = 2:2:index1 if index2 == 6 break end ires = ires + index2; end end ires = number of times (outer loop) number of times (inner loop)arrow_forwardOverview This program will prompt a user for a start and a limit, it will then while-loop through, doubling the iterator each pass, until the limit is reached. Expected Output Example 1 Enter the start of the loop: Enter the limit of the loop: 25 The current value is 3 The current value is 6 The current value is 12 The current value is 24 The last value of current that was less than 25 was 24 Example 2 Enter the start of the loop: 25 Enter the limit of the loop: 102 The current value is 25 The current value is 50 The current value is 100 The last value of current that was less than 102 was 100 Specifications • You should submit a single file called M5A2.py • It should follow the submission standards outlined here: Submission Standards Your program populate an integer named start using input • Your program populate an integer named limit using input Your program must use an iterator named current Your program must move through the values using a while-loop Tips and Tricks That last…arrow_forwardConvert the following for loop statement to a while loop and to a do-while loop: long sum = 0;for (int i = 0; i <= 1000; i++) sum = sum + i;arrow_forward
- Please help me with this question in python using psedocode details. I have attached both pictures below:-arrow_forwardConvert the following for loop statement to a while loop and to a dowhile loop:long sum = 0; for (int i = 0; i <= 1000; i++) sum = sum + i;arrow_forwardWrite code that uses any type of loop. The code should continually ask for a user input and sums all user inputs that are divisible by 2. The loop should continue until the user enters a negative number. The code should output the sum a single time once user entry has completed. You may assume all libraries and namespaces have been previously written into the code, you are just writing everything that would go inside the main function (beyond the return 0:).arrow_forward
- How many times will the loop repeat? for (;;) { } //Some codes...arrow_forwardWrite the following loops. a. Write a while loop that prints all the even numbers from 1 to 100 (inclusive). b. Write do while loop to print all the odd numbers from 1 to 100 (inclusive).arrow_forwardCode in Java using Do-while Loop Write a program that accepts an integer input. If the integer is positive, print the values from the positive integer down to zero. Otherwise, if it is negative, print the values from the negative integer up to zero. Separate each number with a space. Input 1. One line containing an integer Output Enter a number: 5 5 4 3 2 1 0arrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning