I have one program that basically returns a String that can be sometimes one line (which works fine) but other times it can be multiple lines which causes me problems. Basically I have user choose an option that gets sent to second program and based on that option it returns a certain String. However if I put user selection outside my loop it works fine if String returned is multiple lines, but I need it to keep prompting users with options menu until they choose to quit. Here is the code for that:
System.out.print("Enter your choice: ");
fromClient = stdIn.readLine().trim();
while ((fromServer = input.readLine()) != null)
{
System.out.println("Server: " + fromServer);
if (fromServer.equals("Bye"))
break;
if(fromClient.equals("1"))
{
System.out.println("Client: " + fromClient);
output.println(fromClient);
}
if(fromClient.equals("2"))
{
System.out.println("Client: " + fromClient);
output.println(fromClient);
}
if(fromClient.equals("3"))
{
System.out.println("Client: " + fromClient);
output.println(fromClient);
}
if(fromClient.equals("4"))
{
System.out.println("Client: " + fromClient);
output.println(fromClient);
break;
}
}
This as I mentioned above returns multi-line String fine, but it doesn't prompt user anymore for option selection. If I move the user selection inside the loop and multi-line String gets returned it prints one line, asks user for their selection, prints second line, asks user for their selection, prints third line, asks user for their selection...