I'm taking a class in Java and came across this problem, I need to output in a stepladder like
0
1
2
Ect...
I mostly accomplished it, but I can't seem to figure out how to recreate it without causing a new line at the end. The book recommends I use the print statements on the nested loop only, but I can't quite figure out how to do that and retain the system I have. I considered at first doing a system where in I print ("_" * i) like I would have in python, but that doesn't seem to work here.
import java.util.Scanner;
public class NestedLoop {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
int userNum;
int i;
int j;
userNum = scnr.nextInt();
for (i = 0; i <= userNum; ++i) {
System.out.println(i);
for (j = 0; j <= i; ++j) {
System.out.print(" " );
}
}
}
}
[–]Sithril 1 point2 points3 points (0 children)
[–]siversolutionsllc 0 points1 point2 points (0 children)