12345


私信TA

用户名:dotcpp0741805

访问量:69

签 名:

等  级
排  名 38768
经  验 349
参赛次数 0
文章发表 1
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

解题思路:s1和s长度相同,不考虑最后一个字符,s1[i]=(char)s[i]的ASCII码+s[i+1]的ASCII码,考虑最后一个字符:

s1[i]=(char)s[i]的ASCII码+s[0]的ASCII码

注意事项:读入的s中可能包含空格,因此直接读入一行。使用nextline

参考代码:

Scanner scanner = new Scanner(System.in);

String s = scanner.nextLine();

char[] chs = s.toCharArray();

char[] newChs = new char[chs.length];

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

if(i!=chs.length-1) {

newChs[i] = (char)((int)chs[i]+(int)chs[i+1]);

}else {

newChs[i] = (char)((int)chs[i]+(int)chs[0]);

}

}

System.out.println(newChs);


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区