Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Main {
- public static final char[] alphabet = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
- public static int getIndex(char character) {
- for(int i = 0; i < alphabet.length; i++) {
- if(character == alphabet[i])
- return i + 1;
- }
- return -1;
- }
- public static void createSpaces(int index) {
- for(int i = 0; i < index; i++) {
- System.out.print(" ");
- }
- }
- public static StringBuilder createLine(char character) {
- StringBuilder sb = new StringBuilder();
- for(int i = 0; i < getIndex(character); i++){
- sb.append(character);
- if(i + 1 != getIndex(character))
- sb.append(" ");
- }
- return sb;
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- char character = scanner.next().charAt(0);
- int index = getIndex(character);
- int spacesAbove = index - 1;
- int spacesBelow = 1;
- for(int i = 1; i < getIndex(character); i++) {
- createSpaces(spacesAbove);
- System.out.print(createLine(alphabet[i - 1]));
- createSpaces(spacesAbove);
- System.out.println();
- spacesAbove--;
- }
- System.out.println(createLine(alphabet[getIndex(character) - 1]));
- for(int i = getIndex(character) - 1; i >= 1; i--) {
- createSpaces(spacesBelow);
- System.out.print(createLine(alphabet[i - 1]));
- createSpaces(spacesBelow);
- System.out.println();
- spacesBelow++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement