Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

I need a little help with my programming?

For my college Java programming class we've got to use a for loop to print out a pattern of numbers. I've done most of them but unfortunately I can't do the last two. The basic pattern looks like this:

public void displayPatternI(int lines) {

System.out.println("\n\tPattern I\n");

for (int i = 1; i <= lines; i++){

for (int j = 1; j <= i; j++)

System.out.print (j + " " );

System.out.println();

}

}

and it will print out:

1

12

123

1234

etc....

As I've said I've done most of the patterns required to make but I can't understand how to do the last two and the teacher and book are not helpful. I have to have them print out like this:

___1

__21

_321

4321

(I have to use underscores for spaces since Yahoo will just move them to the left if I don't)

etc...

and...

____1

___212

__32123

_4321234

543212345

etc....

I don't usually ask for help on this kind of thing but I don't understand it.

2 Answers

Relevance
  • 8 years ago
    Favorite Answer

    Try two inner loops. One for the spaces and one for the numbers.

    Or perhaps two loops for the numbers in the last case.

    Have fun.

  • 8 years ago

    use the matrix :D

Still have questions? Get your answers by asking now.