Since you said you don't want a full solution, here are some tips.
First, since your table will have to print material from both PatternAI
and PatternBI
on the same line, you should move those loops together. This will involve making the outer loop work for both. You can use more than one variable in a for
loop:
for (int i = 0, j = 0; i < 10 && j < 2; i++, j++)
You also need some way to separate the patterns. You can use spaces, but they will vary in number (in fact the same way the +
's do, so you can use that). Tabs also work and are a bit simpler. You will have to change between the number of tabs you use when the line gets a certain length however.
That's about all there is to it. Let me know if my hints were helpful, or if there is a better way to phrase them.
Here's the full code, if you get stuck:
// Pattern is used for both PatternA and PatternB in this outer loop
// Outer Loop
for (int Pattern = 0; Pattern <= 9; Pattern++) {
// Inner Loop PatternA
for (int PatternAI = 0; PatternAI <= Pattern; PatternAI++) {
System.out.print("+");
}
if (Pattern < 7)
System.out.print(" ");
else
System.out.print(" ");
// Inner Loop PatternB
for (int PatternBI = 9; PatternBI >= Pattern; PatternBI--) {
System.out.print("+");
}
System.out.println();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…