Q:

Write a Java program to print the first letter of your name on the standard output in a nice format. For example, if your name is Ayman, you should print the letter A as:

0

Write a Java program to print the first letter of your name on the standard output in a nice format. For example, if your name is Ayman, you should print the letter A as:

         A

        AA

       A   A

     AAAAA

   A            A

A                  A

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        String name = "Ahmad";
        char firstLetter = name.charAt(0);

        int size = 12;

        int[][] indices = {
                {0, 6},
                {1, 5}, {1, 7},
                {2, 4}, {2, 8},
                {3, 3}, {3, 4}, {3, 5}, {3, 6}, {3, 7}, {3, 8}, {3, 9},
                {4, 2}, {4, 10},
                {5, 1}, {5, 11},
        };

        char[][] matrix = new char[size][size];

        for (int i = 0; i < size; i++) {
            Arrays.fill(matrix[i], ' ');
        }

        for (int[] index : indices) {
            matrix[index[0]][index[1]] = firstLetter;
        }

        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                System.out.print(matrix[i][j]);
            }
            System.out.println();
        }
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now