Solved

How to set the Java console input cursor position?

Posted on 2009-05-17
5
5,724 Views
1 Endorsement
Last Modified: 2012-05-07
I have a very simple java program to prompt user input for certain data on console.

BufferedReader br = new BufferedReader( new InputStreamReader( System.in ));

System.out.printf( "Please enter data 1:" );
data1 =Double.parseDouble( br.readLine());

System.out.printf( "Please enter data 2:" );
data2 =Double.parseDouble( br.readLine());

The problem is when displaying the 2nd prompt, the input cursor moves to the begining of that line. Is there way to control it to move it to the end of the 2nd prompt?


1
Comment
Question by:gs_kanata
5 Comments
 
LVL 17

Assisted Solution

by:Thomas4019
Thomas4019 earned 100 total points
ID: 24408390
Maybe you want something like this. The "\n" is the code for a line break.
		BufferedReader br = new BufferedReader( new InputStreamReader( System.in ));
 
		System.out.printf( "Please enter data 1:\n" );
		double data1 =Double.parseDouble( br.readLine());
 
		System.out.printf( "Please enter data 2:\n" );
		double data2 =Double.parseDouble( br.readLine());

Open in new window

0
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 24408441
works fine here, how are you running it?

0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 200 total points
ID: 24409662
You should be OK with that, but using printf without arguments is redundant. You'd be better off with simply
BufferedReader br = new BufferedReader( new InputStreamReader( System.in ));
 
System.out.print( "Please enter data 1:" );
data1 =Double.parseDouble( br.readLine());
 
System.out.print( "Please enter data 2:" );
data2 =Double.parseDouble( br.readLine());

Open in new window

0
 

Author Comment

by:gs_kanata
ID: 24688420
I ran in the Eclipse. It works fine on the command line.
0
 

Expert Comment

by:boyboyboy711
ID: 37614992
the "\n" here will not solve the problem! it's something like "println", say that "the input value will be at the next line".
But the problem here, The cursor is at the beginning of 2nd line after typing Enter at the 1st line => How to place the cursor at the end of lines (in Eclipse)!

How was this question solved? even the author said it was ok. this site is weird.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 114
servlet  URL Rewriting 1 42
Running JavaFX on JDeveloper 12C 1 52
Notify sent to other threads in Java 9 33
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question