tags:

views:

78

answers:

1

HI I am a new java programmer (very new).

What I want to do/test is (not sure if its recommendable or doable?), we know that

System.out.println("Message");

will output the "Message" in command prompt. Is it possible to display the current time, without having to repeatly use the system.out.println()?

Name, like instead of displaying:

10:00:01
10:00:02
10:00:03

I wand to have liek this: 10:00:0X where X will continue counting

+3  A: 

If you emit a \r (carriage-return) instead of a \n (line-end), in most terminals, the cursor will go back to the start of the same line, so you can "overwrite" the line next time. println automatically adds a \n, but you can use System.out.print (without the ln part;-) to avoid that (you may also have to call method flush to make sure everything you printed was actually output, as opposed to being held in a memory buffer).

Alex Martelli
cool!! I did not know this though.
Winston Chen
so, something liek this: system.out.print("message"); flush();? Sorry, I am still a noob java programmer
javaLearner.java
What's up with this week and \r questions? :) http://stackoverflow.com/questions/2774596/perl-print-back-to-beginning-of-line/2774660#2774660
DVK
BTW, in the interest of completeness, "\r" is referred to as "Carriage Return" character (originating from typewriter days when you "returned the carriage" to the beginning of the line :)
DVK
@DVK: Means, there are more and more new programmers nowadays? Most new programmers starts their programming life by using simple "print" function (thats how I learn my first programming language) lol
javaLearner.java
@javaLearner.java - but carriage return is somewhat of a specialized thing - and I don't recall a single question about it in about a year I was on SO; and this week I saw two... Just to be clear, my comment was amazement at the coincidence, not objection to your question :)
DVK
@DVK: I know, I know haha XD
javaLearner.java