Java的凯撒密码解密程序,出现逻辑错误。

以下代码似乎会让IDE将回车看做字符,怎么回事?
package caesarCipher;
import java.util.Scanner;
public class unlock {
public static void main(String[]args){
Scanner in=new Scanner(System.in);
System.out.println("Please type words,there should be less than 2001.");//警告1
System.out.println("Please check contents,make sure there is no character which goes beyond 40-126(ASCII).The programme only supports English.");//警告2
String words=in.nextLine();
words.replace('\r',' ');
char[] wordsList=new char[2000];
for(int i=0;i<words.length();i++)
wordsList[i]=words.charAt(i);
unlock(wordsList);//解密
for(int i=0;i<words.length();i++)
System.out.print(wordsList[i]);
System.out.println();
}
public static void unlock(char[] words){
for(int i=0;i<words.length;i++){
if(words[i]>=33){
words[i]=(char)(words[i]+219);
}
else if(i>=37&&i<=255){
words[i]=(char)(words[i]-4);
}
else{
System.out.println("\nFind a character goes beyond 33-255 of ASCII!!!Index:"+i);
System.exit(1);
}
}
}
}


化糖
浏览 1592回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP