Here is a simpler version, using decrementing loops and the ternary conditional operator to choose whether to print number or space.
for (int i = 5; i > 0; i--) {
for (int j = 5; j > 0; j--)
System.out.print(j > i ? " " : j);
System.out.println();
}
More Related Contents:
- How to compare variables in a loop, java
- Nested for loop in java. Am I allowed to declare a variable in the outer and increment it in the inner?
- Why is printing “B” dramatically slower than printing “#”?
- How does a for loop work, specifically for(;;)?
- Is there a way to access an iteration-counter in Java’s for-each loop?
- Creating a triangle with for loops
- A for-loop to iterate over an enum in Java
- How to efficiently remove all null elements from a ArrayList or String Array?
- Is there any way to do n-level nested loops in Java?
- Post increment operator not incrementing in for loop [duplicate]
- Null check in an enhanced for loop
- Breaking out of a for loop in Java [closed]
- Using for loop inside of a JSP
- Java: For-Each loop and references [duplicate]
- What's the output of this code written in java?
- Logic behind printing pyramid shape using nested for loops in Java
- get Index of last Element in list without using lastIndexOf() or any other Java/String- Methods [closed]
- updating the variable inside for loop
- Repeat the “if” statement if it has to go to the “else” statement
- How do i print this using For nested loop?
- How do I break out of nested loops in Java?
- Indexes of all occurrences of character in a string
- Performance of traditional for loop vs Iterator/foreach in Java
- Misplaced semicolon in for loop [closed]
- How Iterator’s remove method actually remove an object
- Java: for(;;) vs. while(true)
- Scanner input validation in while loop
- for loop in Java runs 3 times before taking next input
- why is the enhanced for loop more efficient than the normal for loop
- How to Iterate over a Set/HashSet without an Iterator?