ScholarMatic | 24/7 Homework Help

ScholarMatic Will Help You Write Your Essays and Term Papers

Answered » You can buy a ready-made answer or pick a professional tutor to order an original one.

****************************************************************************************** * Program Summary:For, while, and do-while loops; nested…

by | Nov 28, 2023 | computer science

******************************************************************************************

* Program Summary:  For, while, and do-while loops; nested loops

*

add code to create:

*

* a for loop nested inside another for loop

* a while loop

* a do-while loop

*****************************************************************************************/

package prg420week3_codingassignment;

public class PRG420Week3_CodingAssignment {

  public static void main(String[] args) {

  // The following code should print asterisks: 1 on line 1, 2 asterists on line 2,

  // 3 on line 3, 4 on line 4… for as many lines as the variable linesOfAsterisks.

  // To do this, we can use 2 nested for loops. The first for loop is coded for you.

  // You will need to add another for lop, NESTED INSIDE the first, that prints

  // a certain # of asterisks based on the # of times the loop code has been executed.

  // The result should look like this:

  // *

  // **

  // ***

  // ****

  // *****

  // etc.

  int linesOfAsterisks = 5;

  for (int i = 1; i <= linesOfAsterisks; i++) { // for each line…

     // LINE 1. ADD A NESTED FOR LOOP THAT DISPLAYS ONE ASTERISK ON LINE 1, TWO ASTERISKS ON LINE 2, 3 ASTERISKS ON LINE 3, ETC.

  System.out.println();

  }

  //////////////////////////////////////////////////////////////////////

  // Add a while or do-while loop that displays the numbers from 10 to 1 in that order, like so:

  // 10

  // 9

  // 8

  // 7

  // …

  // 1

  //////////////////////////////////////////////////////////////////////

  int num=10;

  //LINE 2. ADD A LOOP THAT DISPLAYS NUMBERS 10 TO 1 IN DECREASING ORDER (HINT: DECREMENT OPERATOR)

  ///////////////////////////////////////////////////////////////////////

  // Write a loop that adds 7s one at a time until the sum becomes > 157.

  // Then print out both the sum and the number of 7s that were aded.

  // Write a while or do-while loop, whichever you think is most appropriate.

  //////////////////////////////////////////////////////////////////////////

  int sum = 0;

  int numberOfSevens = 0;

  //LINE 3. ADD ANOTHER LOOP THAT ADDS 7s UNTIL SUM > 157. THEN DISPLAY SUM AND NUMBER OF SEVENS ADDED.

}

ScholarMatic: Explanation & Answer

Your ready answer from a verified tutor is just a click away for as little as $14.99


  

Click Order Now to get 100% Original Answer Customized to your instructions!

HOME TO CERTIFIED WRITERS

Why Place An Order With Us?

  • Certified Editors
  • 24/7 Customer Support
  • Profesional Research
  • Easy to Use System Interface
  • Student Friendly Pricing

Have a similar question?

PLAGIRAISM FREE PAPERS

All papers we provide are well-researched, properly formatted and cited.

TOP QUALITY

All papers we provide are well-researched, properly formatted and cited.

HIGHLY SECURED

All papers we provide are well-researched, properly formatted and cited.

ScholarMatic: Get Started

Assignment Writing Service

Feel safe and secure when placing an order on our portal!
Fruitful cooperation begins with solid guarantees, and we are professional enough to promise perfect results. Let’s get it started!