I want to be able to enter a number using nextInt() and then print text on the same line as the number I entered. For example...
Scanner scan = new Scanner(System.in);
System.out.print("Enter your number: ");
int x = scan.nextInt(); //After you press 'enter' it goes to the next line and keeps printing text
System.out.print("I want this on the same line as my number!");
And the output would look something like this:
Enter your number: 4356
I want this on the same line as my number!
I开发者_StackOverflow中文版s there a way I can get the text to print right after the number? So it would look something like this?...
Enter your number: 4356 I want this on the same line as my number!
On Windows, I'm pretty sure the answer is "no", because there doesn't seem to be any reverse line feed (see this question: Reverse line feed in Windows / Java).
Have you tried
System.out.print("\rI want this on the same line as my number!");
But note that because the user has to press the Enter key, there's no way (AFAIK) to go a line backwards and erase till the beginning of it.
精彩评论