So I want to make a command line calculator that takes several arguments after the word "Calculator ". But with the following codes I cannot achieve it. In both of those methods the gradle waits to read the line before displaying the word "Calculator ".
Using Scanner
System.out.print("Calculator ");
Scanner sc = new Scanner(System.in);
String inputString;
inputString = sc.nextLine();
String[] args = inputString.split( "\\s+" );
Using BufferReader
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Calculator ");
String str= br.readLine();
String[] args = str.split( "\\s+" );
However the System.out.println("Calculator ") displays the word without any problem. But it's not in line. So it doesn't work as I want. Changing the order of the code lines also didnot help.
System.Console().printf() is also not an option as I am using Intellij IDEA. So can someone please help me with this so that I could get an inline input reader. I also tried to synchronize the printing method by implementing it separately in a method. That didn't work as well.
Finally what I want to achieve is the following format
Calculator max 12 23 25 45
- Here the italicized is the input to be read.
- Bold part should be printed by the program.
before entering input the console ..
after entering the input
Latest Update
So I tried to do the same with a Maven project. Both of the above methods worked perfectly when I did with a maven project in Intellij.
Therefore it must be something to do with gradle's way of running the project. I want to know whether there is a chance for that to happen ?