hello there i am learning java from Apna College and was solving a question of nested loops in which I have to print the pattern:-
**
*
I did this
public class main{ public static void main(String[] args) { for(int line = 1 ; line<=4; line++){ for(int star=4; star>=line; star--){ System.out.print("*"); } System.out.println(); } } }
while mam did like this
public class main{ public static void main(String[] args) { for(int line = 1 ; line<=4; line++){ for(int star=1; star<=4-line+1; star++){ System.out.print("*"); } System.out.println(); } } }
which one’s better
i just want to know which code would be better optimised in cause we have to learn the best thing so which one’s better to adapt
aayushfaang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.