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 6 of 6

Thread: Java Pattern

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

    Default Java Pattern

    Hi, im wondering if someone could help me understand ho I can make this diamond pattern:

    **
     
                                              **********
     
                                       ******************
     
                               **************************  
     
                                       ******************
     
                                             **********
     
                                                  **

    It increases by eight every time up to 26 *, until it decends. Now I got the full diamond pattern to work with a single *, but I'd like to make this one to understand how to chose the pattern signature.

    Doesn't look like it want's to show up like a diamond in this post, but I hope you get the picture.
    Last edited by DoctorBoris; August 29th, 2018 at 08:24 AM. Reason: Added code tags

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java Pattern

    What have you tried so far? What is the problem with what current program outputs?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2018
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Pattern

    I've run this so far :
    public class Lab1
    {
    public static void main(String[] args)
    {
    for(int i = 5; i > -5; i--)
    {
    for(int j = 0; j < i; j++)
    {
    System.out.print(" ");
    }
    for(int j = 0; j >= i; j--)
    {
    System.out.print(" ");
    }
    System.out.println("*");
    }
    }
    }

    and it gives me a starting point from 1=, adding 2 every time up to 9
    what I want is to start with 2 and add 8 every line up to 26 then down to 2 again with a total of 7 lines.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java Pattern

    I want is to start with 2 *s and add 8 every line up to 26 *s then down to 2 *s again with a total of 7 lines.
    Ok, what have you tried?
    Can you describe what the program will decide as it prints each line?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Aug 2018
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Pattern

    Thanks for sticking with me, and answering my maybe silly questions

    I've tried to change the values of j and i, but I can't seem to find the right combination to start with two stars and end with two stars.

    I really don't know what I want the program to decide technically, basically because I don't yet understand how to write my pattern. But I want it to print a diamot shape like this.
    Attachment 3378
    im working in VS code btw.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java Pattern

    how to write my pattern.
    Make a list of what should be printed on each line for all 7 lines and look for a pattern that relates what is on a line with the number of the line.
    Post the list here. The first line would be something like this:
    line1: print 6 spaces, print 2 *s, print end of line

    What goes on the remaining 6 lines?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. What is builder design pattern in Java?
    By Nirali in forum The Cafe
    Replies: 0
    Last Post: July 19th, 2018, 12:51 AM
  2. Regex to parse application log using java and grok pattern
    By ankita shukla in forum What's Wrong With My Code?
    Replies: 0
    Last Post: December 20th, 2017, 11:06 PM
  3. Pattern printing in Java
    By arunjib in forum Loops & Control Statements
    Replies: 4
    Last Post: July 1st, 2011, 04:05 PM
  4. Regular Expression pattern - complex pattern syntax
    By SmartAndy in forum Algorithms & Recursion
    Replies: 3
    Last Post: June 7th, 2011, 04:40 AM
  5. Urgent need a java regex pattern
    By mallikarjun_sg in forum Java Theory & Questions
    Replies: 1
    Last Post: May 6th, 2010, 05:51 AM