【问题标题】:java program: decrypting side of a a rail fence cipherjava程序:解密铁路围栏密码的一面
【发布时间】:2016-04-14 01:36:45
【问题描述】:

我正在努力让循环在每个必需的索引中放置一个字符,我的错误在 plainText.charAt(count)。错误如下:

无法从字符串转换为字符

任何提示我如何解决这个问题,谢谢。

char array[][]= new char [key][plainText.length()];
             for (int row = 0; row < array.length; row++) {
                 for (int col = 0; col < array[row].length; col++) {

                 }
             }
             int g = plainText.length();
             int count=0;
             int c=0;
             int a=0, b=0;
             int init =(2*key)-2;
             a = init -2;
             b = 2;
             for (int row = 0; row < array.length; row++) {
                for (int col = row; col < array[row].length;) { // take out row++ want to stay on first row
                    if ( count != g){
                        if(row==0||row==key-1){
                            col+=init;
                            array[row][col]= " " + plainText.charAt(count); 
                        }else {
                            array[row][col]= "" + plainText.charAt(count);
                        }
                    }

                }enter code here
            }

【问题讨论】:

    标签: java arrays encryption char


    【解决方案1】:

    删除空字符串" ",你就有了:

    array[row][col] = plainText.charAt(count);  
    

    并添加 col++ 增量,如:

      for (int col = row; col < array[row].length;col++) {
    

    【讨论】:

    • 很酷,谢谢,现在它给出了越界异常,必须再看一遍
    • @b.d 删除这一行:col+=init;
    • 如果我删除它,它不会在下一个列上放置一个字符
    • @b.d 没问题 remove col+=init;并像上面一样在你的循环中添加 col++
    猜你喜欢
    • 2018-11-24
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-20
    • 1970-01-01
    • 1970-01-01
    • 2017-04-02
    相关资源
    最近更新 更多