首页 > 解决方案 > OOP 中的字符串使用 | 重复不应该重复的字母

问题描述

我正在尝试 OOP JavaScript,我的问题是下一个:

String message = Keyboard.StringReader("Introduce the message to codificate: ");

String key = Keyboard.StringReader("Introduce the key code: ");

Encryptation sequence_1 = new Encryptation(message,key);

当我放入带空格的字符串时,没有问题。它执行下面的代码:

//This is the constructor, who takes the space
public Encryptation(String p, String o){

    this.message = p;
    this.keycode = o;

}

//这是问题所在:当我漫游字符串并且它发生在空格所在的位置时,程序将其更改为空格之前的字母。如果this.message为“AAA AAA”,则messageToken()返回“AAAAAAA”。所以我不知道如何解决这个问题。有什么帮助吗?

public char messageToken(){

    int i = 0
    i++;

    return this.message.charAt(i);
}

标签: stringoop

解决方案


看起来您的 messagetoken 总是返回 charAt(1)


推荐阅读