错误:")"预期错误:表达式非法开始


//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,所以您的所有评论将不胜感激......方法8.是空的,它不返回任何值,对吗?如果我想把 8 放进 9,displayEncryptedMessage(String originalMessage, String encryptedMessage);,这是 Id 作为参数放的吗?为什么我会收到这些错误?

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

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

displayEncryptedMessage(String originalMessage, String encryptedMessage);

应该是

 displayEncryptedMessage(originalMessage, encryptedMessage);

调用该方法时,需要传递如下值:

displayEncryptedMessage(originalMessage, encryptedMessage);

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

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

最新更新