Results 1 to 4 of 4
- 07-22-2011, 10:00 PM #1
Noob
- Join Date
- Jul 2011
- Location
- M-I-yayo
- Posts
- 11
- Rep Power
- 0
how to keep on the same line. Help needed.
hello everyone. I would like to know how I can have a string appear on the same line after the program is run. i.e. after the user enters "hours", i want the text hours to appear next to it on the same line and not the next. sorry if I didnt' post this correctly.
public static void main (String[] args)
{
int hours, mins, secs, totalsecs;
Scanner inhours = new Scanner (System.in);
Scanner inmins = new Scanner (System.in);
Scanner insecs = new Scanner (System.in);
System.out.print ("Please enter the number of hours: ");
hours = inhours.nextInt(); System.out.print ("hours.");
System.out.println ();
mins = inmins.nextInt(); System.out.print ("minutes.");
System.out.println ();
secs = insecs.nextInt(); System.out.print ("seconds.");
System.out.println ();
System.out.println ();
int HOURS = hours * 3600;
int MINS = mins * 60;
int SECS = secs * 1;
totalsecs = HOURS + MINS + SECS;
System.out.println ("You entered " + hours + " hours," + mins + " minutes,"
+ secs + " seconds.");
System.out.println ("The given amount of time translates to "
+ totalsecs + " seconds.");
}
}
- 07-22-2011, 10:08 PM #2
As far as I know, you can't. Certainly putting the code on the same line isn't going to accomplish it. Very interesting attempt though.
You have to hit enter to submit the information to the program, thus causing a newline. That's why most people do a print statement beforehand doing something like Hours: instead.- Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
- +Rep people for helpful posts.
- 07-22-2011, 10:11 PM #3
Noob
- Join Date
- Jul 2011
- Location
- M-I-yayo
- Posts
- 11
- Rep Power
- 0
- 07-22-2011, 10:58 PM #4
Java's support for console I/O is extremely poor. I revisited this issue recently, thinking that the newish java.io.Console allowed reading single characters instead of whole lines. Nope... not on the JRE I'm using, anyway.
Get in the habit of using standard Java naming conventions!
Similar Threads
-
Constructors pls explan the code line by line in comments
By vibaviattigala in forum New To JavaReplies: 1Last Post: 02-19-2011, 05:03 AM -
How to read file line by line with fixed number of characters
By trkece in forum New To JavaReplies: 1Last Post: 02-13-2011, 04:09 PM -
tracing java application line by line using netbeans
By chandrasekhar123 in forum NetBeansReplies: 1Last Post: 08-03-2010, 03:46 PM -
Formatting java command line output - Multi line string
By dricco in forum New To JavaReplies: 2Last Post: 07-02-2010, 03:20 PM -
Need to read an .ini and .abook file line by line (both files contain texts)
By ollyworks in forum Java AppletsReplies: 4Last Post: 09-10-2009, 11:18 AM
Bookmarks