Results 1 to 3 of 3
Thread: Create Pattern
- 10-12-2010, 02:09 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 8
- Rep Power
- 0
Create Pattern
I've actually been working on this same problem, and I've been having trouble as well. Though I've found out the pattern is supposed to consist of two triangles like this:
1 333
22 22
333 1
4444
Also, we're only supposed to use nested loops. Strings are not allowed. So far I have this:
for (int k = 0; k <= 2; k++){
for (int n = 0; n <= 1 * k; n++){
System.out.print(" ");
}
for (int m = 2; m>= k; m--){
System.out.print((3-k));
}
System.out.println();
}
for (int i = 0; i <= 3; i++){ //1
for (int j = 0; j <=i; j++){ //22
System.out.print(1 + i); //333
} //4444
System.out.println();
}
}}
Which produces this:
333
22
1
1
22
333
4444
The spacing on the top triangle should be correct. Is there a way to combine the two? I've messed around with the brackets but nothing seems to be working.
Edit: Sorry about that, Fubarable.Last edited by bossanova; 10-12-2010 at 02:22 AM.
-
OP, please do not hijack other's posts. If you've a question related to another thread, then start your own thread and provide a link to the related one. I've moved your post from this thread most-my-trouble-identifying-pattern into its own thread.
- 10-12-2010, 04:07 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
Class pattern to generate following pattern:-
By vxs in forum New To JavaReplies: 5Last Post: 07-14-2010, 11:15 PM -
Create an Asterisk Pattern in Java
By kaurpower in forum New To JavaReplies: 1Last Post: 03-17-2010, 01:00 AM -
Pattern
By mtyoung in forum Advanced JavaReplies: 9Last Post: 04-07-2009, 02:17 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks