Solved

How to set the Java console input cursor position?

Posted on 2009-05-17
5
5,251 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
Comment Utility
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
Comment Utility
works fine here, how are you running it?

0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 200 total points
Comment Utility
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
Comment Utility
I ran in the Eclipse. It works fine on the command line.
0
 

Expert Comment

by:boyboyboy711
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now