Welcome to Dream.In.Code
Become a Java Expert!

Join 150,183 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,125 people online right now. Registration is fast and FREE... Join Now!




text at end of readline help.

 
Reply to this topicStart new topic

text at end of readline help.

icde4fn
23 Aug, 2008 - 11:17 AM
Post #1

New D.I.C Head
*

Joined: 22 Aug, 2008
Posts: 5

this is the snippit of code from the calc, i want to have it appear as mass of object user inputkg's
but I cant figure out how to have the kg's appear after the input.readdouble
can anyone help with this?


CODE
// obtaining mass in kg
System.out.print(" (kg) mass of " + object + "= ");
mass= input.readDouble ();

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Text At End Of Readline Help.
23 Aug, 2008 - 12:18 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Hopefully I am understanding you correctly but this will probably help...

java

// obtaining mass in kg
mass = input.readDouble ();

// Assuming that mass is defined as a Double data type
System.out.print("mass of " + object + "= " + mass.toString());


Here we fetch the mass from the user and then display it in the print statement by calling its toString() function. This makes it a string for printing.

If this is not what you were after, you might want to clarify further. smile.gif
User is offlineProfile CardPM
+Quote Post

icde4fn
RE: Text At End Of Readline Help.
23 Aug, 2008 - 01:31 PM
Post #3

New D.I.C Head
*

Joined: 22 Aug, 2008
Posts: 5

QUOTE(Martyr2 @ 23 Aug, 2008 - 01:18 PM) *

Hopefully I am understanding you correctly but this will probably help...

java

// obtaining mass in kg
mass = input.readDouble ();

// Assuming that mass is defined as a Double data type
System.out.print("mass of " + object + "= " + mass.toString());


Here we fetch the mass from the user and then display it in the print statement by calling its toString() function. This makes it a string for printing.

If this is not what you were after, you might want to clarify further. smile.gif


imagine if it were on paper and you had to fill in the blank, so question is:
Mass of object = _____ kg
the blank would be for the user input and the kg would appear behind that. yes it is a double btw.
User is offlineProfile CardPM
+Quote Post

nick2price
RE: Text At End Of Readline Help.
23 Aug, 2008 - 02:21 PM
Post #4

D.I.C Regular
***

Joined: 23 Nov, 2007
Posts: 338



Thanked: 12 times
My Contributions
If you just want kg to be outputted after the mass, i cant see where your input for your mass is inputted, but the output would be
CODE
System.out.print(" (kg) mass of " + object + "= " + mass + "Kg");


Just output the kg as a string after you output the mass.
User is offlineProfile CardPM
+Quote Post

Unknown Hero
RE: Text At End Of Readline Help.
23 Aug, 2008 - 08:37 PM
Post #5

New D.I.C Head
Group Icon

Joined: 4 Sep, 2007
Posts: 44



Thanked: 8 times
Dream Kudos: 50
My Contributions
I think what you're trying to do is impossible, because after user types number of kilograms, he presses ENTER key (new line).
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 03:56AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month