char[] words = new char[str.length()]; words = str.toCharArray(); for(int i=0;i<words.length;i++) { if((words[i]>=97&&words[i]<122)||(words[i]>=65&&words[i]<90)) { words[i] = (char) (words[i]+1); }else if(words[i]==122){ words[i] = 97; }else if (words[i]==90){ words[i] = 65; }else { } System.out.print(words[i]); }
程序中的words【】的作用仅仅是当作计数器的判断条件么?
南山的疆 2020-02-07 07:37:58 |
确实创建两个字符数组有点多余,可以去掉一个,import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); String str = input.nextLine(); char[] words = new char[str.length()]; words = str.toCharArray(); for(int i=0;i<words.length;i++) { if((words[i]>=97&&words[i]<122)||(words[i]>=65&&words[i]<90)) { words[i] = (char) (words[i]+1); }else if(words[i]==122){ words[i] = 97; }else if (words[i]==90){ words[i] = 65; }else { } System.out.print(words[i]); } } }
南山的疆 2020-02-07 07:46:27 |
不好意思哈,不知道为什么代码复制到这里会变成这样子?
啥也不是的辣椒油 2020-02-07 19:58:37 |
@dwr44 ahhh 么事么事,明白啦
C语言程序设计教程(第三版)课后习题10.1 (C语言代码)浏览:1516 |
校门外的树 (C语言代码)浏览:1166 |
C语言程序设计教程(第三版)课后习题6.3 (Java代码)浏览:695 |
C语言程序设计教程(第三版)课后习题8.3 (Java代码)浏览:1402 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:949 |
【金明的预算方案】 (C++代码)浏览:873 |
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:583 |
【明明的随机数】 (C语言代码)浏览:845 |
P1000 (C语言代码)浏览:911 |
出圈】指针malloc版浏览:377 |