0

我是 Java 和一般编程的新手。这让我感到莫名其妙,我觉得我可能只需要放弃我拥有的东西并走另一条路,但我不知道该走哪条路。

下面是我为将用户的一行翻译成盲文而编写的代码。有用!不幸的是,它垂直工作。在使用三行创建盲文后,如何使下一个盲文字符出现在前一个盲文字符的旁边而不是在它的下方?

import java.util.*;

public class Program4
{

    public static String code1 = ". |";
    public static String code2 = " .|";
    public static String code3 = "..|";
    public static String code4 = "  |";

    public static void main(String[] args)
    {
        Scanner keyboard = new Scanner(System.in);

        System.out.println("Program 4 by Ross Walker");
        System.out.println();

        String s;
        System.out.println("Please give a line to translate");
        s = keyboard.nextLine();

        for(int i = 0; i < s.length(); i++)
        {
            char c = s.charAt(i);
            if(c == '1' || c == 'a')
            {
                //new Program4().letterA(s.charAt(i));
                System.out.printf("%s%n%s%n%s%n", code1, code4, code4);
                System.out.println();
            }

            if((c == '2' ) || (c == 'b'))
            {
                System.out.printf("%s%n%s%n%s%n", code1, code1, code4);
                System.out.println();
            }
            if((c == '3') || (c == 'c'))
            {
                System.out.println(code3);
                System.out.println(code4);
                System.out.println(code4);
                System.out.println();
            }
            if((c == '4') || (c == 'd'))
            {
                System.out.println(code3);
                System.out.println(code2);
                System.out.println(code4);
                System.out.println();
            }
            if((c == '5') || (c == 'e'))
            {
                System.out.println(code1);
                System.out.println(code2);
                System.out.println(code4);
                System.out.println();
            }
            if((c == '6') || (c == 'f'))
            {
                System.out.println(code3);
                System.out.println(code1);
                System.out.println(code4);
                System.out.println();
            }
            if((c == '7') || (c == 'g'))
            {
                System.out.println(code3);
                System.out.println(code3);
                System.out.println(code4);
                System.out.println();
            }
            if((c == '8') || (c == 'h'))
            {
                System.out.println(code1);
                System.out.println(code3);
                System.out.println(code4);
                System.out.println();
            }
            if((c == '9') || (c == 'i'))
            {
                System.out.println(code2);
                System.out.println(code1);
                System.out.println(code4);
                System.out.println();
            }
            if((c == '0') || (c == 'j'))
            {
                System.out.println(code2);
                System.out.println(code3);
                System.out.println(code4);
                System.out.println();
            }
        }
    }
}

我只写了字母表中的 j。如果这是我能完成它的唯一方法,我会继续,但如果可能的话,我希望你能帮助以正确的方式完成它。

4

0 回答 0