0

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.

3
Contributors
4
Replies
9
Views
7 Years
Discussion Span
Last Post by justinwarner
0

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

0

>>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();
  }
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.