0
//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
4

2 回答 2

11

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

displayEncryptedMessage(String originalMessage, String encryptedMessage);

应该

 displayEncryptedMessage(originalMessage, encryptedMessage);
于 2013-08-13T10:13:38.890 回答
0

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

displayEncryptedMessage(originalMessage, encryptedMessage);

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

Note: Method can also accept the Type or Subtype of the type.
于 2013-08-13T11:28:40.467 回答