vendredi 6 novembre 2020

Java Diamond Pattern - with Char increment/decrement [closed]

Implement a program that creates the diamond shapes shown below. The height of the figures is controlled by the variable int figHeight. The height specifies the number of lines and may only take positive odd values less than or equal to 53.

Within the hash the output starts with the character 'A' and is then increased by the ASCII 1 value 1 with each step to the right (e.g.: after A follows B, then C, etc.). In the two middle columns of the hash, the same character is output twice and then the ASCII value is reduced by 1 with each step to the right (e.g.: after D follows C, then B, etc.). In order for the backslash ('') to be output, you must write '\'. This is a so-called escape sequence. For the realization of the example no methods, strings or arrays (also methods from these classes du ̈rfen are not allowed). Only use System.out.print() to draw the figures on the console.

System.out.println("Input: ");
    Scanner input = new Scanner(System.in);
    int figHeight = input.nextInt();
    if (figHeight % 2 == 1 && figHeight <= 53 && figHeight > 0) {

   // task

    /*Code that may help:
         for (int i = 0; i <= maxRow; i++) {
            int alphabet = 65;
            for (int j = maxRow; j > i; j--) {
                System.out.print(" ");
            }
            System.out.print('/');
            for (int k = 0; k <= i; k++) {
                System.out.print((char) (alphabet + k));
            }
            for (int l = i - 1; l >= 0; l--) {
                System.out.print((char) (alphabet + l));
            }
            System.out.print('\\');
            System.out.println();
        }*/

    } else {
        System.out.println();
        System.out.println("Format incorrect!");

output picture

Aucun commentaire:

Enregistrer un commentaire