错误:')'预期错误:非法启动表达式

时间:2013-08-13 10:11:01

标签: java

//8.    
//----------------------------------------------------------------
//-------- Display orignal and encrypted message information
//----------------------------------------------------------------
    private void displayEncryptedMessage(String originalMessage, String encryptedMessage) {
        System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.println("Enter Message to be encrypted: ");
        System.out.println("");
        System.out.println("");
        System.out.println("");
        System.out.println("   Plain Text : " + originalMessage);

    }

// 9
//----------------------------------------------------------------
// Encrypted it by substituting the character with the corresponding character in the cipher.
// 
//----------------------------------------------------------------
    private void encrypt(String cipher){
      int letterPosition;
      String encryptedMessage = "";
      String originalMessage = Keyboard.readInput();

      displayEncryptedMessage(String originalMessage, String encryptedMessage);

      for (letterPosition=0; letterPosition<originalMessage.length(); letterPosition++){
        char replaceCipherLetter = cipher.charAt(letterPosition);
        encryptedMessage += replaceCipherLetter;}
      System.out.println("   Cipher Text: " + encryptedMessage);
      } 

我是Java的新手,所以你的所有评论都会非常感激... SInce方法8.无效,它不会返回任何值吗?如果我想将8放入9,displayEncryptedMessage(String originalMessage, String encryptedMessage);,那是Id作为参数吗?为什么我会收到这些错误?

  Error: ')' expected 
  Error: illegal start of expression

2 个答案:

答案 0 :(得分:11)

当你调用方法时,你必须只传递值,方法调用时不允许类型声明。

displayEncryptedMessage(String originalMessage, String encryptedMessage);

应该是

 displayEncryptedMessage(originalMessage, encryptedMessage);

答案 1 :(得分:0)

在调用方法时,您需要传递以下值:

displayEncryptedMessage(originalMessage, encryptedMessage);

声明方法将接受的参数类型是方法定义的一部分。

Note: Method can also accept the Type or Subtype of the type.