需要使用嵌套数组解决硬件问题

时间:2019-06-04 18:28:21

标签: java

所以我有一个硬件作业,我需要使用嵌套数组从字母表中选择一个字母。我不知道为什么我的代码无法正常工作。我通过电子邮件发给我的教授。他说要自己解决。我需要帮助

public static void main(String[] args) {
        char[] first2 = new char[]{'a', 'b'};char[] fifth2 = new char[]{'i', 'j'};char[] ninth2 = new char[]{'q', 'r'};
        char[] second2 = new char[]{'c', 'd'};char[] sixth2 = new char[]{'k', 'l'};char[] tenth2 = new char[]{'s', 't'};
        char[] third2 = new char[]{'e', 'f'};char[] seventh2 = new char[]{'m', 'n'};char[] eleventh2 = new char[]{'u', 'v'};
        char[] fourth2 = new char[]{'g', 'h'};char[] eighth2 = new char[]{'o', 'p'};char[] twelf2 = new char[]{'w', 'x'};
        char[] thirteenth2 = new char[]{'y', 'x'};
        char[][] first4 = new char[][]{first2, second2};char[][] second4 = new char[][]{third2, fourth2};char[][] third4 = new char[][]{fifth2, sixth2};
        char[][] fourth4 = new char[][]{seventh2, eighth2};char[][] fifth4 = new char[][]{ninth2, tenth2};char[][] sixth4 = new char[][]{eleventh2, twelf2};
        char[][][]first8 = new char[][][]{first4, second4};char[][][]second8 = new char[][][]{third4, fourth4};char[][][]third8 = new char[][][]{fifth4, sixth4}; char[][][] last = new char[][][]{new char[][]{thirteenth2}};
        char[][][][]first16 = new char[][][][]{first8, second8};char[][][][]remainder = new char[][][][]{third8, last};
        char[][][][][] alphabet = new char[][][][][]{first16, remainder};
        System.out.println("enter a 5 digit number? : ");
        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine();
        char cha = aplhabet[input[0]][input[1]][input[2]][input[3]][input[4]];
    }

1 个答案:

答案 0 :(得分:-1)

我在这里看到一些语法/一般错误。

  1. twelf2thirteenth2都有x。您可能正在考虑将z放入thirteenth2
  2. aplhabet在最后一行中拼写错误
  3. 您无法使用String访问来索引[],而需要使用charAt。而且即使那样,您仍需要将字符转换为整数,因为您无法使用char访问数组。

我不确定您要在这里实现什么,因此,在没有MCVE的情况下,SO通常对硬件问题不满意,因此您可能在这里找不到想要的答案。