+ 1

Explain this code:-

public class jay{ public static void main(String[] args) { int rows = 5; for(int i = rows; i >= 1; --i) { for(int space = 1; space <= rows - i; ++space) { System.out.print(" "); } for(int j=i; j <= 2 * i - 1; ++j) { System.out.print("* "); } for(int j = 0; j < i - 1; ++j) { System.out.print("* "); } System.out.println(); } } }

14th Jul 2020, 5:46 AM
HALAI JAYESHKUMAR
HALAI JAYESHKUMAR - avatar
4 Answers
+ 3
Please show your code here using code playground: https://www.sololearn.com/post/75089/?ref=app How to ask a better question: Tips when asking in this forum: https://www.sololearn.com/discuss/333866/
14th Jul 2020, 5:47 AM
Gordon
Gordon - avatar
+ 6
Either attach your code in the description or paste it to the code playground and send here
14th Jul 2020, 5:49 AM
Nilesh
Nilesh - avatar
+ 1
Remove public keyword from class jay and run the program. it prints inverted equilateral triangle of *.
14th Jul 2020, 6:46 AM
Krk
0
similar like this int rows = 5; String spaces="", stars1="", stars2=""; for(int i=rows; i>=1; --i) { //all rows stars1 = "* ".repeat(i); // for 2 (j: 5..9, 4..7, 3..5, 2..3, 1..1) stars2 = "* ".repeat(i-1); // for 3 (j: 0..3, 0..2, 0..1, 0..0) System.out.println( spaces +stars1 +stars2); spaces += " "; // for 1 }
14th Jul 2020, 9:39 AM
zemiak