Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started