65 873
Assignments Done
99,1%
Successfully Done
In October 2018

Answer to Question #64579 in Java | JSP | JSF for Sherlynn

Question #64579
Write a JAVA program that asks the user to enter time in 24hour format. Convert it into 12-hour format. Repeat the program by asking whether the user wants to continue (yes continue, no: stop the program) or not. h -> 0 to 23 m -> 0 to 59 short codes please
Expert's answer
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Format {

public static void main(String[] args) {
try {
Scanner sc = new Scanner(System.in);
String contin = "";
while(!contin.equals("no")){
System.out.println("Time in 24 hour format(example 23:12):");
String _24HourTime = sc.nextLine();
SimpleDateFormat _24HourSDF = new SimpleDateFormat("HH:mm");
SimpleDateFormat _12HourSDF = new SimpleDateFormat("hh:mm a");
Date _24HourDt = _24HourSDF.parse(_24HourTime);
System.out.println(_12HourSDF.format(_24HourDt));
System.out.println("Entet your answer(yes continue, no: stop the program):");
contin = sc.nextLine();
}
} catch (Exception e) {
e.printStackTrace();
}
}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions