Member Avatar for hillary.vitzthum

I have already seen that someone posted this question a couple of years ago. I do not want any one to flat out give me the answer. I hav the code written, I just cannot figure out why the pattern won't look like this:

1
12
123
1234
12345
123456

123456
12345
1234
123
12
1

Here is my code:

public class TwoPatterns {
  // DECLARE CONSTANTS FIRST
  // Constructor. This replaces the default "no argument" constructor
  public TwoPatterns() {
    super();
  }

  // DESCRIBE EACH METHOD
  private void executeTwoPatternsLogic() {
    //Display pattern 1
    for (int i = 1; i <= 6; i++){
        for (int j = 1; j <= i; j++){
            System.out.print(j);
            } 
        System.out.println("");
    }   
    for (int i = 6; i >= 1; i--){
        for (int j = 6; j >= i; j--){   
            System.out.print(j);
        }
        System.out.println("");
    }
  }
  // main method. Instantiates object; directs it to compute values
  public static void main(String[] args) {
    TwoPatterns tmp = new TwoPatterns();
    tmp.executeTwoPatternsLogic();
    System.exit(0);
  }
}

Anything stand out? Just maybe say look at line..... again??? I am not looking for someone to tell, me I have just been staring at it for a long time and need fresh eyes.

Recommended Answers

All 3 Replies

So, what pattern does your code generate?

Have a look at line 18.
The inner loops should always start printing a 1.

It generates two of the same patterns. And actually indeed that last parter to look like a upside down pyramid. His is driving me crazy!! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.