# Thread: Most of my trouble is identifying a pattern

1. Member
Join Date
Oct 2010
Posts
2
Rep Power
0

## Most of my trouble is identifying a pattern

Howdy all:

My apologies if this has been addressed; I tried searching for a while with no luck.

I'm trying to find a way to code a nested for loop that produces the following output:

1333
2222
3331
4444

To be honest, I don't know where to start. For instance, I spent 3 hours today trying to find some complex formula for what turned out to be simple "squared" powers.

If anyone can help in any way possible, I'd be greatly appreciative.

2. You could do it by creating a 1-D array of String that holds the four numbers above as Strings, and then use two for loops nested together, the first to grab the String (row), the second to loop through each char of the String (using the String method, charAt(...)) and printing it. Or for another way, you could create a 2D array of int and loop through this with nested for loops.

3. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
14
Is there a pattern to those numbers?  Sorry, I've just read the post's title.
Last edited by pbrockway2; 10-10-2010 at 05:30 AM.

4. Member
Join Date
Oct 2010
Posts
2
Rep Power
0
Thanks all for the quick responses and input!

I've been playing around with the code, but can't get anything to stick to what I need.

This is what I have so far:
Last edited by ElkNinja; 10-12-2010 at 12:44 AM.

5. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
14
Fubarable's suggestion is a good one. Follow it. Ask if you are unsure what he meant. (And say if you haven't learnt anything about arrays.)

Have you compiled that code? I ask because it's a bit pointless writing code that doesn't compile. You can't really start with a bunch of vaguely computer looking stuff and keep changing bits until it compiles, runs and produces the output you want. Well, you can: but it's the hard way of doing things.

Scrap what you've got. You know that your Java program will require a main() method right? So start by writing that (consult your text book if need be) and make sure it compiles. Then work on what F suggested.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•