A computer screen displaying Java code with the text 'Java Programming'" Caption: "Coding in Java
Coding in Java

Displays the pattern on the screen

Table of Contents


package chapter1;

public class TableAndChair {
    public static void main(String[] args) {
        System.out.println("X                           X\n");
        System.out.println("X                           X\n");
        System.out.println("X        XXXXXXXXXX         X\n");
        System.out.println("XXXX     X        X      XXXX\n");
        System.out.println("X  X     X        X      X  X\n");
        System.out.println("X  X     X        X      X  X");

Explain Code

This code is written in Java and defines a class named “TableAndChair” in the “chapter1” package. The class contains a single method, “main”, which is the entry point of the program.

When the program is executed, the “main” method will be executed and it will print several lines of text to the console that depict a rough ASCII art representation of a table and a chair.

Each line is printed using the “System.out.println” statement, which outputs the text passed as an argument to the console. The text is a combination of X’s, spaces, and newline characters (‘\n’) which, when printed to the console, create the ASCII art image of a table and a chair.