如何在Java中的加密字符串[复制]

问题描述 投票:-3回答:1

这个问题已经在这里有一个答案:

我希望通过字符串这是我在尝试添加+1(ASCII)每一个字符的字符串加密

public static string encrypt(string str){
for(int i = 0; i < str.length(); i++){
    int x = str.charAt(i) ;
    x = x + 1; 
}

//现在,我怎么完成这个循环会产生一个加1,每一个字符加密字符串的新字符串?

java
1个回答
0
投票

我建议你尝试以下方法:

Public static string encrypt(string str){
    String result = "";   
    for(int i=0; i<str.length() ; i++){
        int x = str.charAt(i) ;
        x = x+1 ;
        result+= Character.toString((char)x);
    }
    return result;
 }
© www.soinside.com 2019 - 2024. All rights reserved.