Question: 1 6 . 8 . 1 : PRACTICE: Branches * * : 2 4 - hour time 2 4 - hour time ( also known
: PRACTICE: Branches: hour time
hour time also known in the US as military time is widely used around the world. Time is expressed as hours since midnight. The day starts at : and ends at : Write a program that converts ampm time to hour time. The input is two numbers and a string. If the input is pm the output should be : If the input is am the output should be :
Hints:
Think of how each hour should be handled. am am becomes what? am becomes what? pm pm Group the hours into cases that should be handled similarly eg am to am are handled the same
Declare variables for hoursAmPm, minAmPm, and hours Note that minutes for hour time remain the same as for ampm so no extra variable is needed.
Use an ifelse statement to detect each case, and set the hours appropriately.
When outputting hour check if the hour is just check for If so output a So will be output as Do the same when outputting the minutes.
import java.util.Scanner;
public class main
public static void mainString args
Scanner scnr new ScannerSystemin;
Type your code here.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
