Results 1 to 5 of 5
  1. #1
    ElkNinja is offline Member
    Join Date
    Oct 2010
    Posts
    2
    Rep Power
    0

    Default 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. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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. #3
    pbrockway2 is online now Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,573
    Rep Power
    12

    Default

    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 06:30 AM.

  4. #4
    ElkNinja is offline Member
    Join Date
    Oct 2010
    Posts
    2
    Rep Power
    0

    Default

    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 01:44 AM.

  5. #5
    pbrockway2 is online now Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,573
    Rep Power
    12

    Default

    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

  1. help with identifying components of a gui
    By jaytee in forum New To Java
    Replies: 1
    Last Post: 03-08-2010, 03:28 AM
  2. Identifying System Architecture-Urgent
    By Robert_85 in forum Advanced Java
    Replies: 2
    Last Post: 08-16-2009, 05:34 AM
  3. Replies: 2
    Last Post: 03-24-2009, 06:02 PM
  4. uniquely identifying a browser window
    By mrak in forum Advanced Java
    Replies: 3
    Last Post: 01-17-2009, 07:29 AM

Posting Permissions

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