Facing problem while trying to print using PrintWriter.
Problem Description:
I am expecting to print the
Pressoptions first then take the user input but usingout.printlni can't do that. It's not printing the options while i run the program. It just waits for an input while i give the input it then prints the Press options.
Note: if i use System.out.println then it works as expected.
Tried it like below
public class Calculator {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
StringTokenizer took = new StringTokenizer(" ");
String operator;
// System.out.println("Press '+' for Additon");
// System.out.println("Press '-' for Subtraction");
// System.out.println("Press '*' for multiplication");
out.println("Press '+' for Additon");
out.println("Press '-' for Subtraction");
out.println("Press '*' for multiplication");
out.println("Press '/' for Division");
operator=in.readLine();
switch (operator) {
case "+":
out.println("Add");
break;
case "-":
out.println("Subtract");
break;
case "*":
out.println("Multiply");;
break;
case "/":
out.println("Division");
break;
}
in.close();
out.close();
}
}
Input:
*
Output:
Press '+' for Additon
Press '-' for Subtraction
Press '*' for multiplication
Press '/' for Division
Multiply
autoFlush.