用字符写的字母

时间:2017-04-19 22:11:17

标签: java character letters

标题可能令人困惑,但一个例子将澄清:

用户输入一串字符:ab

控制台显示(理论上):

example

但我所能做的就是展示:

actual display

如何在示例中显示文字?

这是课程:

- >主:

import java.util.Scanner;

public class CaractereDinAlteCaractereMain {

    public static void main(String[] args) {

        Scanner userInput = new Scanner(System.in);
        Caractere ochei = new Caractere();


        System.out.println("Introduceti caractere: ");        //insert characters
        String caracter = userInput.nextLine().toUpperCase();

        for (int i = 0; i < caracter.length(); i++) {
            ochei.litera(caracter.substring(i, i + 1));
            System.out.println(ochei.getCaracter());
        }
    }

}

- &GT; Caractere:

public class Caractere {

    private String caracter;

    public String getCaracter() {
        return caracter;
    }

    public String litera(String userInput) {

            switch (userInput) {

            case "A":
                caracter = "     *     \n" +
                           "    * *    \n" +
                           "   *****   \n" +
                           "  *     *  \n"+
                           " *       * \n";
                break;

            case "B":
                caracter = " *****  \n" +
                           " *    * \n" +
                           " ****** \n" +
                           " *    * \n"+
                           " *****  \n";
                break;

            case "C":


            }

            return caracter;

    }

}

1 个答案:

答案 0 :(得分:-2)

删除/ n所以它在打印结束时看起来像打印一条新行,将“B”放在它下面的行上。

                caracter = " *     \n" +
                       "    * *    \n" +
                       "   *****   \n" +
                       "  *     *  \n"+
                       " *       * ";