java字符后移_java把字符串参数往后移3位后输出

//我想把字符串参数往后移3位后输出packagepassword;importjava.io.IOException;classjiami{Strings1;Stringjiami(Strings)throwsIOException{inti,j;Stringallstring="ABCDEFGHIJKLM...

//我想把字符串参数往后移3位后输出

package password;

import java.io.IOException;

class jiami{

String s1;

String jiami(String s)throws IOException{

int i,j;

String allstring="ABCDEFGHIJKLMNOPQRSTUVWXYZABC";

this.s1=s;

for(j=0;j<=s1.length();j++)

{

char s2=s1.charAt(1);

for(i=0;i<=allstring.length();i++){

char allstring1=allstring.charAt(i);

char allstring2=allstring.charAt(i+3);

if(allstring1==s2)

s1=s1.replace(s2, allstring2);

}

}

return s1;

}

}

/**

*

* @author 1

*/

public class password {

/**

* @param args the command line arguments

*/

public static void main(String[] args)throws IOException {

// TODO code application logic here

jiami newpassword=new jiami();

String str="ABCDEFH";

System.out.print(newpassword.jiami(str));

}

}

出错如下:

init:

deps-jar:

Warning: password\password.java modified in the future.

Compiling 1 source file to F:\password\build\classes

compile-single:

run-single:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 29

at java.lang.String.charAt(Unknown Source)

at password.jiami.jiami(password.java:20)

at password.password.main(password.java:41)

Java Result: 1

成功生成(总时间:0 秒)

怎么改呢?

如传入参数“ABCF”,则替换成“DEFI”输出!也就是每个字符按字母表顺序 用 往后移3位的字符 替换!

展开

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值