Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: HOW to do it?

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default HOW to do it?

    print pattern like the fllowing using loops structure:

    .........
    ........
    .......
    ......
    .....
    ....
    ...
    ..
    .

    --- Update ---

    class Exercise4{
    public static void main(String args[]){
    int a =9;

    while (a>0){
    System.out.println(".");
    a--;
    }

    }
    }

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: HOW to do it?

    What does that code do?

    Can you write out, in words, what the pattern is?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    27
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: HOW to do it?

    You could try a string array containing every stage of the dot pattern and having a for loop cycle through the elements.

  4. #4
    Member jdv's Avatar
    Join Date
    Jul 2014
    Location
    This Land
    Posts
    73
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: HOW to do it?

    Hint: what you want to do is a very simple version of a histogram: https://en.wikipedia.org/wiki/Histogram

    Hint: the number of dots and the number of lines are a function of a related loop iteration limit.

    Hint: start with a method that takes two parameters, and prints a single line of n characters.

    (It strikes me that this is an excellent intro Coding Golf exercise. If I leave out all readability I get something like 190 chars. But I'm actually making a method call, which eats up lots of space. 146 with no method call, but still using readable looping. This is like 40 VM instructions.)
    Last edited by jdv; August 5th, 2014 at 10:56 AM.

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: HOW to do it?

    Quote Originally Posted by BenjaminJ View Post
    You could try a string array containing every stage of the dot pattern and having a for loop cycle through the elements.
    This is not the solution to this problem.

    This is a pretty standard first-year homework assignment, so it's better to try to steer the OP in the right direction by asking him questions rather than offering full solutions.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!