caesar加密代码中的问题 [英] Question in caesar encryption code
本文介绍了caesar加密代码中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个凯撒加密代码
有些错误,请求帮助我
this code of caesar encryption
have some error ,, pleas help me
package encryption;
import java.util.*;
/**
*
* @author Toshiba
*/
public class Encryption {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// ENCR n =new ENCR();
Scanner S = new Scanner(System.in);
System.out.print(" Enter the text");
String massege = S.next();
System.out.print(" Enter the kay");
int key = S.nextInt();
}
public String NN ( String massege , int kay )
{
String STR= "ABCDEFGHIJKLMNOPQRSTWXYZ" ;
char current;
String chyfer= "";
for (int i=0; i<=massege .length();i++)
{
current = massege .charAt(i);
for (int y= 0 ; y<=STR.length(); y++) {
if(current==STR.charAt(y))
{
chyfer + = STR.charAt((kay+y)%26);
return chyfer ;
}
}
}
return chyfer ;
}
}
推荐答案
在行中
Hi,
In the line
chyfer + = STR.charAt((kay+y)%26);
+
和 =
之间的空格。删除空格:
there''s a space between +
and =
. Remove the space:
chyfer += STR.charAt((kay+y)%26);
希望这有帮助。
Hope this helps.
修改后的错误得到以下代码,但它不运行>>
是什么原因?
After modified the mistakes got the following code, but it is not run >>
What is the reason ؟؟
package encryption;
import java.util.*;
public class Encryption {
public static void main(String[] args) {
Encryption enc = new Encryption();
Scanner S = new Scanner(System.in);
System.out.println(" Enter the text");
String massege = S.next();
System.out.println(" Enter the kay");
int key = S.nextInt();
System.out.println( " the word chyfer is " + enc.NN( massege, key) );
}
public String NN ( String massege , int kay )
{
String STR= "ABCDEFGHIJKLMNOPQRSTWXYZ" ;
char current;
String chyfer= "";
for (int i=0; i<=massege .length();i++)
{
current = massege .charAt(i);
for (int y= 0 ; y<=STR.length(); y++) {
if(current==STR.charAt(y))
{
chyfer+=STR.charAt((kay+y)%26);}
}}
return chyfer ;
}}
thi是输出
输入文字
jg
输入kay
2
线程main中的异常java.lang.StringIndexOutOfBoundsException:字符串索引out of范围:24
at java.lang.String.charAt(String.java:686)
at encryption.Encryption
thi is the output
Enter the text
jg
Enter the kay
2
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 24
at java.lang.String.charAt(String.java:686)
at encryption.Encryption
这篇关于caesar加密代码中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文