为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

化糖 2016-07-28 14:23:55
以下代码似乎会让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); } } } }
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 1590 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信