2014-04-14 4 views
0

나는 프로그램을 진행하기 위해 "입력"을 두 번 할 필요가있는 문제에 직면하고있다. 누군가 나를 계몽 할 수 있는가?두 번 입력해야합니다. 왜?

public void run() { 
    try { 
     out.write("Enter message to encrypt: \n"); 
     out.flush(); 

     while (true) { 

      entry = in.readLine(); 
      result = caesarCipher(entry); 

      out.write("The encrypted message is " + result); 
      out.write("\tType q to end else type another message to encrypt"); 
      out.flush(); 

     } 
    } catch (IOException e) { 
     System.out.println(e); 
    } 
} 

내 클라이언트 클래스는 서버 클래스에 연결할 때, 내가 암호화 메시지를 입력해야합니다

public EncryptClient() throws IOException { 
    Socket cSock = new Socket("LocalHost", portNumber); 
    Reader iRead = new InputStreamReader(cSock.getInputStream()); 
    input = new BufferedReader(iRead); 

    userTerminal = new BufferedReader(new InputStreamReader(System.in)); 
    output = new OutputStreamWriter(cSock.getOutputStream()); 

    while (true) { 
     String line = input.readLine(); 
     System.out.println(line); 
     line = userTerminal.readLine(); 

     if (line.equals("q")) { 
      break; 
     } 
     output.write(line + "\n"); 
     output.flush(); 
    } 
} 

이 클라이언트 측에서 이상이지만, 더블 보여주기 위해 필요한 입력 결과. 누군가가 나를 계몽 할 수 있습니까?

답변

1

ReadLine은 흐름 제어를 중지합니다.

코드에서 코드는 두 개가 있습니다. readLine .readLine(); // (줄을 두 번 덮어 씁니다.) 중복되었습니다. 그것을 제거하십시오. 너 괜찮을거야.

관련 문제