On line no no of stars
1 1
2 3
3 5
4 3
5 1
*
***
*****
***
*
i cant but i want lean now.
i cant but i want lean now.
i need more explanation on it.
i need more explanation on it.
no you don't. you gave all the explanation to find the answer in your first post:
it's a PATTERN that you want to PRINT
there are only very basic techniques used there, no doubt your teacher showed you those.
2 for loops.
Outer: 1 to 5 for the lines.
Inner: Depending on the index of the first loop you will decide how many stars will be printed. The number of stars will be the number of times the inner loop will run.
Also:
System.out.println() : Changes lines
System.out.print("*") : Prints '*' at the same line
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.