Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. What are the three parts of a for loop statement? 2. Write a for loop that displays the numbers 1 through 10. The first

1. What are the three parts of a for loop statement? 2. Write a for loop that displays the numbers 1 through 10. The first few lines of output are num = 1 num = 2 num = 3 3. Write a for loop that displays the numbers 20 through 1. The first few lines of output are num = 20 num = 19 num = 18 4. Write a loop that finds the sum of all even numbers from 2 to 100. 5. Write a loop that finds the sum of all squares from 1 to 100. In other words, write a loop that computes the following sum: 12+22+32+42++992+1002. 6. Write a loop that finds the sum of all multiples of 3 from 6 to 99. 7. Convert the while loop to a for loop int i = 0; while(i < 10){ System.out.println("i = " + i); i++; } 8. Convert the while loop to a for loop int i = 100; while(i > 50){ System.out.println("i = " + i); i--; } 9. Convert the following code segment to a while loop: for (int k = 1; k < 10; k++) System.out.print(k + " "); 10. Convert the following code segment to a while loop: for (int k = 10; k > 1; k--) System.out.print(k + " "); 11. Convert the following code segment to a while loop: for (int k = 1; k < 10; k = k*2) System.out.print(k + " ");

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions

Question

=+ a. What happens to the labor demand curve?

Answered: 1 week ago