Help writing nested for loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tzpike05
    New Member
    • Apr 2010
    • 2

    Help writing nested for loop

    Hi there. Struggling with this one. I'm to write a program that has this output:

    0
    10
    210
    3210
    43210
    543210
    6543210
    76543210
    876542310
    9876543210

    Also, I can only have two print statements. One that prints a newline character and one that prints a single digit. I've rearranged my code numerous times and here is what I have now:

    public class Loops
    {
    public static void main (String [] args)
    {
    for (int num0 = 0; num0 <= 9; num0++)
    {
    System.out.prin tln();
    for (int num1 = 9; num1 >= num0; num1--)
    {
    System.out.prin t(num1);
    }
    }
    }
    }

    This will output:

    9876543210
    987654321
    98765432
    9876543
    987654
    98765
    9876
    987
    98
    9

    I've also written the code to output:

    0
    01
    012
    0123
    01234
    012345
    0123456
    01234567
    012345678
    0123456789

    Any help is greatly appreciated.
  • tzpike05
    New Member
    • Apr 2010
    • 2

    #2
    No one has any advice?

    Comment

    • Dheeraj Joshi
      Recognized Expert Top Contributor
      • Jul 2009
      • 1129

      #3
      What is the problem you are acing?

      Regards
      Dheeraj Joshi

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        Look at the lines and answer the following:
        0
        Starts with _, ends with _.
        10
        Starts with _, ends with _.
        210
        Starts with _, ends with _.
        3210
        Starts with _, ends with _.
        43210
        Starts with _, ends with _.
        543210
        Starts with _, ends with _.
        6543210
        Starts with _, ends with _.
        76543210
        Starts with _, ends with _.
        876542310
        Starts with _, ends with _.
        9876543210
        Starts with _, ends with _.

        for(START, END, num1--);

        Comment

        Working...