hw6 - three System.out.print() calls:...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 302 Homework 6 - Due Monday, July 11 Name: 1. Convert the following for loop into an equivalent set of instructions that only uses one while loop and no other types of loops. for(int i = 0; i < 45; i++) { System.out.println("Looping"); } 2. How many times do the following loops execute? (a) for(int i = 1; i < 5; i++) { . . . } (b) for(int i = 0; i <= 12; i += 2) { . . . } (c) for(int i = 0; i > 0; i--) { . . . } (d) do { . . . } while (false); 3. Write nested for loops that print the following pattern to the screen. You may only have
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: three System.out.print() calls: System.out.print(&quot;*&quot;) , System.out.print(&quot; &quot;) , and System.out.println(&quot;&quot;) , each written only once . Hint: Use one loop to keep track of the current line, one to print spaces, and one to print stars. * *** ***** ******* ********* 4. Write a code fragment to randomly generate an integer value between 1 and 11. (You need not write a class or method; just the lines of code relating to this speciFc task.)...
View Full Document

Ask a homework question - tutors are online