Java петли я не могу понять
I have 3 tasks I need to output. (The other comments are instructions to me). The 3 tasks are next to the first 3 asterisks. Can you assist me again please? Here it is: * 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. }
Что я уже пробовал:
Я даже не могу начать это. Мне бы не помешала помощь, пожалуйста.