Results 1 to 5 of 5
- 10-10-2010, 04:18 AM #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.
-
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.
- 10-10-2010, 05:21 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Is there a pattern to those numbers? [edit] Sorry, I've just read the post's title.
Last edited by pbrockway2; 10-10-2010 at 05:30 AM.
- 10-10-2010, 06:05 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.
- 10-10-2010, 06:17 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
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.
Similar Threads
-
help with identifying components of a gui
By jaytee in forum New To JavaReplies: 1Last Post: 03-08-2010, 02:28 AM -
Identifying System Architecture-Urgent
By Robert_85 in forum Advanced JavaReplies: 2Last Post: 08-16-2009, 04:34 AM -
Trouble implementng an Adapter/Strategy (GoF) design pattern
By Algatron in forum Advanced JavaReplies: 2Last Post: 03-24-2009, 05:02 PM -
uniquely identifying a browser window
By mrak in forum Advanced JavaReplies: 3Last Post: 01-17-2009, 06:29 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks