-
January 18th, 2013, 10:29 AM
#1
one entry line of code, Java
Hello everyone, I am new to Java and need some help. the question is as follows.....
Create a modified version of this project as follows:
Allow the user to enter the hours, minutes, and seconds in one prompt instead of three separate prompts. That is, the user would be allowed to represent 1 hour 28 minutes and 42 seconds by entering:
1:28:42
This will require you to use the colon ( as a delimeter in the scanned input.
I have the following code which works well, but I need to adjust it to where I only have one manual entry rather than three.
import java.util.Scanner;
import java.io.*;
public class userinput {
public static void main(String[] args)
{
Scanner time = new Scanner(System.in);
String hour;
String min;
String sec;
String cotime;
hour = time.next();
min = time.next();
sec = time.next();
cotime = (hour + ":" + min + ":" + sec);
System.out.print(cotime);
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|