0
我試圖幫助一個同事解碼來自他的朋友的一封信,並且他厭倦了自己做數學。我把它作爲一個嘗試使用Java來幫助他在計算機進行數學運算時加快解密速度的機會。我最初試圖做一次5個角色的塊,但我的陣列是一團糟,他認爲他希望一次完成一個角色。簡單的Java加密/解密 - (錯誤:意外的類型||必需:變量找到:值)
下面是我的代碼:
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
試圖讀取所有這些其他人的這種錯誤的問題只是做我的頭不疼,因爲我把握不住他們首先遇到了問題。
那些陳述沒有意義。你覺得他們做什麼? – SLaks 2011-12-19 22:14:03
可能你的意思是'finish_letter_num =(letter_num)+(number_code);'etc? – 2011-12-19 22:15:11
這正是我的意思......哇,我現在覺得很愚蠢。謝謝! – ElijahGartin 2011-12-19 22:19:06