Concept explainers
Rewrite the following for statement as a while loop (and possibly some additional statements):
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Absolute Java (6th Edition)
Additional Engineering Textbook Solutions
Database Concepts (7th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Modern Database Management
Java: An Introduction to Problem Solving and Programming (8th Edition)
Starting out with Visual C# (4th Edition)
- Rewrite the following for loop as a while loop. java for(int sum = 0, count = 0; count < 50; count = count + 1, sum = sum + count);arrow_forwardShow the corresponding for loop for this while loop do it in pseudocode . Keep it simple please ( java for beginners) start Declarations num count = 0 while count < 6 output “Good Day” set count = count + 1 endwhile stoparrow_forwardWrite a program in Java using the for loop, the while loop and the do- while loop to print the numbers from 10 to 100 as follows: 10 20 30 40 50 60 70 80 90.100arrow_forward
- (Python) Which is the correct answer? This loop is best when you want the loop to run X amount of times. a. loopX b. while c. for d. do whilearrow_forwardA Java for loop has the following general form: for(start; test; increment) { statements } in the parentheses after the keyword "for", _____ provides the starting point for the loop, _____tells what to adjust before the next loop iteration, and _____ is a boolean expression that when true, lets the loop to continue and when false, causes the loop to terminate.arrow_forwardConvert the following while loop into for loop : int x =0; while(x <=10) { System.out.println("X : " + x); x+=2; } note : a java codearrow_forward
- Count and sum the same? yes or, no, why? 1. { int sum = 0; for ( int count = 0; count < 10; count++ ) { System.out.print( count + " " ); sum = sum+count; } } 2. { int sum = 0; for ( int count = 0; count < 10; count++ ) { System.out.print( count + " " ); sum = sum+count; } System.out.println("\nAfter the loop count is: " + count ); }arrow_forwardRewrite the following as a for loop. int i = 0, value = 0;while (i <= 20){if (i % 2 == 0 && i <= 10)value = value + i * i;else if (i % 2 == 0 && i > 10) value = value + i;elsevalue = value - i;i = i + 1;}cout << "value = " << value << endl;What is the output of this loop?arrow_forwardGiven the following program segment: int i;int value = 3;for (i = 0; i < 5; i++)value = value * (i + 1) + i;cout << "value = " << value << endl;write a while loop and a do...while loop that have the same output.arrow_forward
- True or False ___(4) In a while loop, the body of the loop has to be executed at least once whether the test is true or not. ___(5) In Java a while loop can be changed to a for loop and vice versa. ___(6) Java statement !( x / 3 = = 6 ) || y*3 = = -6 ; evaluates to false if x=19 and y= -2arrow_forwardwrite this in pseudocode #4 – In pseudocode, write a for-loop that decreases from 100 to 2 by 2s. Inside the loop, print the value of the loop variable unless the value is from 60 to 80 (inclusive). Use only 1 if-statement. Do NOT write Python code! Write your answer below: #5 – Review the decision structure given below. If myAnswer > 20 Then myAnswer = myAnswer - 25Else If myAnswer <= 5 Then If myAnswer < 0 Then myAnswer = 10 If myAnswer < 3 Then myAnswer += 10 Else myAnswer += 1Else myAnswer = 9 If myAnswer < 10 ThenmyAnswer += 1 Display myAnswer What are the results displayed when the decision structure above executes for each given value below:If myAnswer = 6 then myAnswer = myAnswer = 15 then myAnswer = myAnswer = 30 then myAnswer = myAnswer = 2 then myAnswer = myAnswer = -1 then myAnswer = #6 – 2-dimensional arrays can be thought of as containing rows…arrow_forwardJAVA program Write a while loop that prints all the even numbers from 1 to 100 (inclusive). and another while loop to print all the odd numbers from 1 to 100 (inclusive).arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning