내 프로그램의 모든 오류에 대해 댓글을 달았습니다. 내 프로그램의 요점은 내 입력 파일을 사용자가 무엇을 입력하여 이동하는 것입니다. 내가 주석 처리 한 오류는 모두 의미가 없기 때문에 무의미합니다. 컴퓨터가 원하는 방식으로 컴퓨터를 읽지 못하기 때문입니다. 내가 토큰 중 하나에 대해 언급 한 오류 중 하나와 혼동해서는 안됩니다. "," 다른 것은 "("및 ")"입니다. 이 모든 것들은 내가 주석을 달았던 라인의 어딘가에서 세미 콜론을 예상하는 오류이다.토큰에 구문 오류,; 기대 되는가?
import java.util.*;
import java.io.*;
class CaesarCipher
{
public static void main (String [] args) throws FileNotFoundException
{
Scanner keyboard = new Scanner(System.in);
System.out.println("What shift should I use? ");
int shift = keyboard.nextInt();
System.out.println("What is the name of the input file? ");
String name = keyboard.next();
File f = new File(name);
Scanner inFile = new Scanner(f);
System.out.println("What is the name of the output file? ");
String text = keyboard.nextLine();
PrintWriter outFile = new PrintWriter(text);
String encrypted = "";
while (inFile.hasNextLine())
{
String line = inFile.nextLine();
if (shift == 1)
encrypted = caesarEncipher(line, shift);
else if (shift == 2)
encrypted = caesarDecipher(line, shift);// the method caesarDecipher(java.lang.String, int) is undefined for the type CaesarCipher
System.out.println(encrypted);
outFile.println(encrypted);
}
}
static String caesarEncipher(String text ,int shift) throws FileNotFoundException
{
String t = "";
int i = 0;
while (i < t.length())
{
if (shift < 0)
{
shift = (shift % 26) + 26;
}
int move = (char) ((text.charAt(0) - 'A' + shift) % 26 + 'A');
t += move;
i++;
System.out.println(t);
outFile.println(t);
return "DONE!";
}
// for each token listed, it expects the semi colon.
static String caesarDecipher(String text, int shift) throws FileNotFoundException // Syntax error on token "(", "," , ")", ; expected
{
return caesarEncipher(input, -shift);
}
}
}
당신은'caesarEncipher' 메쏘드에서'}'을 닫지 않습니다. – pb2q
코드를 올바르게 포맷하면 컴퓨터가 어떻게 작동하는지 (대부분의 경우) 읽을 수 있습니다. –