Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中的字符数组_Java_Arrays_Character - Fatal编程技术网

Java中的字符数组

Java中的字符数组,java,arrays,character,Java,Arrays,Character,因此,我试图做的是描述,因此步骤如下: 用四个字母的单词读 将字符串解析为字符并将字符转换为整数。将这些十进制值存储在数组中 乘以你的加密矩阵 打印编码的单词 乘以加密矩阵的倒数并打印出来 但是,我遇到的问题是打印编码的单词。在我打印单词的最底部,什么也没有显示。我做错什么了吗 public static void main(String [] args){ Scanner input = new Scanner(System.in); String word = "give"; {

因此,我试图做的是描述,因此步骤如下:

用四个字母的单词读

将字符串解析为字符并将字符转换为整数。将这些十进制值存储在数组中

乘以你的加密矩阵

打印编码的单词

乘以加密矩阵的倒数并打印出来

但是,我遇到的问题是打印编码的单词。在我打印单词的最底部,什么也没有显示。我做错什么了吗

public static void main(String [] args){

Scanner input = new Scanner(System.in);
String word = "give"; {

    while(word.length() == 4){
        word=word;}

    while(word.length() != 4){
        word=input.next();
        }


    int[][] wordArray =  new int[2][2];
    wordArray[0][0] = (int)word.charAt(1);
    wordArray[0][1] = (int)word.charAt(2);
    wordArray[1][0] = (int)word.charAt(3);
    wordArray[1][1] = (int)word.charAt(4);

    int[][] encriptionArray = new int [2][2];
    encriptionArray[0][0] =  1;
    encriptionArray[0][1] = 2;
    encriptionArray[1][0] = 3;
    encriptionArray[1][1] = (4);


    int[][] printArray = new int [2][2];
    printArray[0][0]= wordArray[0][0]*encriptionArray[0][0]+ wordArray[0][1]*encriptionArray[0][1];
    printArray[0][1]= wordArray[0][1]*encriptionArray[0][1]+ wordArray[0][1]*encriptionArray[1][1];
    printArray[1][0]= wordArray[1][0]*encriptionArray[0][0]+ wordArray[1][1]*encriptionArray[1][0];
    printArray[1][1]= wordArray[0][1]*encriptionArray[1][0]+ wordArray[1][1]*encriptionArray[0][1];

    System.out.print(printArray[0][0]);
    System.out.print(printArray[0][1]);
    System.out.print(printArray[1][0]);
    System.out.print(printArray[1][1]);

}


}
}


这是一个无限循环。字=字;什么也不做。由于单词的长度为4,while循环将连续执行。学习使用调试器,并逐行执行代码,以查看它在做什么。

将while循环更改为以下内容:

while (true) {
    System.out.print("Enter 4-letter word:");
    word = input.nextLine();
    if(word.length()==4){
        break;
    }
}

我的问题有问题吗?
while (true) {
    System.out.print("Enter 4-letter word:");
    word = input.nextLine();
    if(word.length()==4){
        break;
    }
}