Hey,
So, in our book (I'm doing them for practice, I don't know if we have to actually do them), it says to display the pattern:

J    A     V     V    A
    J   A A     V   V    A A
J   J  AAAAA     V V    AAAAA
 JJ   A     A     V    A     A

So, I wrote:

public class Main {

    public static void main(String[] args)

    {
    String j = "J";
    String a = "A";
    String v = "V";
        System.out.println("    "+j+"    "+a+"     "+v+"     "+v+"    "+a);
        System.out.println("    "+j+"   "+a+" "+a+"     "+v+"   "+v+"    "+a+" "+a);
        System.out.println(j+"   "+j+"  "+a+a+a+a+a+"     "+v+" "+v+"    "+a+a+a+a+a);
        System.out.println(" "+j+j+"   "+a+"     "+a+"     "+v+"    "+a+"     "+a);

    }

}

Which yes, it works, but I was wondering (First chapter of the book), is there any way that you think they meant to do it? Or do you think this is fine?

Thanks,
Justin W.

Recommended Answers

All 4 Replies

Since it is the first chapter it makes sense if you should practice on concatenate strings and the difference between print and println.

Okay,
Thank you. I just wanted to make sure I was doing it right =).

>>Which yes, it works, but I was wondering (First chapter of the book), is there any way that you think they meant to do it?

Since it is the first chapter of the book, I think they mean to do it as follows:

public class JavaPattern
{
  public static void main(String[] args)
  {
    /* Print newline before displaying the pattern. */
    System.out.println();
    
    /* Print the pattern. */
    System.out.println("    J    A     V     V    A");
    System.out.println("    J   A A     V   V    A A");
    System.out.println("J   J  AAAAA     V V    AAAAA");
    System.out.println(" JJ   A     A     V    A     A");
    
    /* Print newline after displaying the pattern. */
    System.out.println();
  }
}

Thanks sneak and tux =). Have a great day!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.