Is there a way in the console to stop java from starting a new line when hit enter?

For example, if the user enters 7 * 4, I want him to output 7 * 4 = 28

Instead

7 * 4
= 28

I searched for a couple of hours and did not find anything. Thanks for any help in advance.

public class RecursiveMultiplication { public static void main(String[] args) { Console console = System.console(); String input[] = new String[2]; String multiplicand, multiplier; int product; while(true) { input = console.readLine("?> ").split("\\D+"); multiplicand = input[0]; multiplier = input[1]; product = multiply(Integer.parseInt(multiplicand), Integer.parseInt(multiplier)); console.printf(" = %d", product); } } public static int multiply(int multiplicand, int multiplier){ if(multiplier == 0) return 0; if(multiplier % 2 == 0) return multiplicand + multiplicand + multiply(multiplicand, multiplier - 2); return multiplicand + multiply(multiplicand, --multiplier); } 

}

+4
source share
1 answer

This is a limitation of the console on which your Java program is running. It’s not easy to get around, but you can take a look at the Java Curses Library . Personally, I don’t think it’s worth the hassle. Instead, it would be easier to write a Java Swing GUI.

+4
source

Source: https://habr.com/ru/post/1392632/


All Articles