Answer to Question #64580 in Java | JSP | JSF for Sherlynn
2017-01-13T05:14:10-05:00
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
1
2017-01-16T06:45:36-0500
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 !
Learn more about our help with Assignments:
Java JSP JSF
Comments
Leave a comment