Very basic Java nested for loop issue
I'm having a hard time trying to get this code to start at 5 spaces and
reduce to 0 spaces, subtracting a space every line.
public class Prob3 {
public static void main(String[]args) {
for (int x=1; x<=5; x++)
{
for (int y=5; y>=1; y--)
{
System.out.print(" ");
}
System.out.println(x);
}
}
}
Current output is (should be 5 spaces):
5
4
3
2
1
I'm happy with the progress so far but I need to get something closer to
this:
1
2
3
4
5
I feel like I'm pretty close
Edit got it.
public class Prob3 {
public static void main(String[]args) {
for (int x=1; x<=5; x++)
{
for (int y=5; y>=x; y--)
{
System.out.print(" ");
}
System.out.println(x);
}
}
}
No comments:
Post a Comment