简单Java加密/解密(错误:意外类型| |必需:找到变量:值)
我正试图帮助一位同事破解他朋友的一封信,他已经厌倦了自己做数学题。我借此机会尝试使用Java来帮助他在计算机进行运算的情况下更快地解密。起初我试着一次做5个字符的块,但我的数组太乱了,他认为他还是想一次做一个字符
下面是我的代码:
import java.io.*;
class CharlieEncryption
{
public static void main(String args[]) throws IOException
{
CharlieEncryption app;
app = new CharlieEncryption();
app.appMain();
}
BufferedReader stdin;
String inString;
String encrypt;
String decrypt;
String[] alphabet = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","Y","X","Z"};
String letter;
int letter_code = 0;
int number_code = 0;
int letter_num = 0;
int finish_letter_num = 0;
String finish_letter;
// appMain module (Call all modules here)
public void appMain() throws IOException
{
Input();
Mode();
if(encrypt.equals("Y"))
{
Encrypt();
Output();
}
else
{
Decrypt();
Output();
}
}
//Module to recieve Input
void Input() throws IOException
{
//Requesting Input
System.out.print("Please input character");
letter = stdin.readLine();
//Converting Letter to Number
for(int j = 0; j < 25; j++)
{
if(letter.equals(alphabet[j]))
{
letter_num = j;
}
}
//Requesting Input for Code
System.out.println("Please input code for the character");
inString = stdin.readLine();
number_code = Integer.parseInt(inString);
}
//Module to ask if user wants to encrypt or decrypt
void Mode() throws IOException
{
System.out.println("Would you like to encrypt? Y or N");
encrypt = stdin.readLine();
if(encrypt.equals("N"))
{
System.out.println("Would you like to decrypt? Y or N");
decrypt = stdin.readLine();
}
}
//Module to Encrypt Text
void Encrypt()
{
(letter_num) + (number_code) = finish_letter_num;
//Converting the finished number to a letter
for(int i = 0; i < 25; i++)
{
if(finish_letter_num == i)
{
finish_letter = alphabet[i];
}
}
}
//Module to Decrypt Text
void Decrypt()
{
(letter_num) - (number_code) = finish_letter_num;
//Converting the finished number to a letter
for(int i = 0; i < 25; i++)
{
if(finish_letter_num == i)
{
finish_letter = alphabet[i];
}
}
}
//Module to Output Encrypted Text OR Decrypted Text
void Output()throws IOException
{
System.out.println("Result" + finish_letter);
}
}
以下是错误:
CharlieEncryption.java:78: error: unexpected type
(letter_num) + (number_code) = finish_letter_num;
^
required: variable
found: value
CharlieEncryption.java:91: error: unexpected type
(letter_num) - (number_code) = finish_letter_num;
^
required: variable
found: value
2 errors
试图用这个错误阅读所有其他人的问题只会让我头疼,因为我无法理解他们最初遇到问题的代码
# 1 楼答案
试试看
而不是
试试看
而不是
希望这就是你所需要的