Question 2: Write the code for a nested for-loop that prints the following outputs. You should be able to do it with either a single for-loop or a nested for-loop for each of the outputs. Output 1: 0 2 4 6 3 5 7 9 6 8 10 12 9 11 13 15 12 14 16 18 15 17 19 21 Output 2: The first row is empty! 1 2 4 3 6 9 4 8 12 16
Added by Melissa Q.
Close
Step 1
The pattern continues for 4 rows. Show more…
Show all steps
Your feedback will help us improve your experience
Willis James and 61 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Write a method called showTwos that uses a while loop to show the factors of 2 in a given integer. For example, the following calls should return the values shown: showTwos(7) = 7 showTwos(18) = 2 * 9 showTwos(68) = 2 * 2 * 17 showTwos(120) = 2 * 2 * 2 * 15 showTwos(192) = 2 * 2 * 2 * 2 * 2 * 2 * 3
Willis J.
Write a Java program that declares an array to hold 12 integers. The contents of the array should be the values 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24. Use a for-loop to initialize the contents of the array to these values. After initializing the array to these values, the program should display the contents of the array. Suggested output: The contents of the array are: Index Value 0 2 1 4 Etc.....
Cora M.
Write a program using loops to generate following output. 12 x 2 = 24 11 x 2 = 22 10 x 2 = 20 9 x 2 = 18 8 x 2 = 16 7 x 2 = 14 6 x 2 = 12 5 x 2 = 10 4 x 2 = 8 3 x 2 = 6 2 x 2 = 4 1 x 2 = 2
Sarvesh S.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD