1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
marshall27 [118]
3 years ago
14

Design a program that will receive a valid time in the 24-hour format (e.g. 2305) and convert to its equivalent 12-hour format (

e.g. 11:05 PM). Assume 0000 in 24-hour format is 12:00AM in 12-hour format. The program should continue accepting inputs until a sentinel value of 9999 is entered. Hint: Use System.out.printf statements with "d" (Links to an external site.) to match output format. Ex: If the input is: g
Computers and Technology
1 answer:
coldgirl [10]3 years ago
8 0

Answer:

import java.io.*;

public class Main

{

  public static void main(String[] args) throws IOException {

      BufferedReader bufferObject=new BufferedReader(new InputStreamReader(System.in));

      String stringObject=bufferObject.readLine();

      while(!stringObject.equals("99:99AM")){

      System.out.println(convertedTime(stringObject));

      stringObject=bufferObject.readLine();

      }

  }

  public static String convertedTime(String stringObject){

  String s=stringObject.substring(stringObject.length()-2);

  String[] timeObject=stringObject.substring(0,5).split(":");

  if(s.equals("AM")){

  if(timeObject[0].equals("12")) return "00"+timeObject[1];

  else return timeObject[0]+timeObject[1];

  }

  else{

  if(timeObject[0].equals("12")) return "12"+timeObject[1];

  else{

  int hours=Integer.valueOf(timeObject[0]);

  timeObject[0]=String.valueOf(12+hours);

  return timeObject[0]+timeObject[1];

  }

  }

 

  }

}

Explanation:

  • Inside the main method run a while loop until stringObject is not equal to the string "99:99AM".
  • Call the convertedTime method and display the results.
  • Use the same hours and minutes except for 12th hour If the time is in AM.
  • Use "00" instead of 12, if it is 12th hour.
  • Add hours to 12, if the time is in PM and don't change anything in case of 12.
You might be interested in
For what purpose is IT used in business?
stealth61 [152]

Answer:

manufacturing

improving

customer care

transportation

human resource management

Explanation:

business communication use technology to improve their services or products as a way of gaining competitive advantage.

6 0
3 years ago
View the attached pic
mr_godi [17]
The answer is the first one
4 0
3 years ago
Read 2 more answers
Editing is important because it allows you to
asambeis [7]
Answer A is the answer, as it combines all choices in the list. One can check the overall structure.
8 0
3 years ago
When workers demonstrate patience, are able to manage there emotions, and get along with other employees, which skills are being
LenKa [72]
The skill thar is being displayed I thing is being outgoing and loyal
6 0
3 years ago
Read 2 more answers
The enter/return key is struck by the
Black_prince [1.1K]

Answer:

B

Explanation:

8 0
3 years ago
Read 2 more answers
Other questions:
  • An Open Authorization (OAuth) access token would have a _____ that tells what the third party app has access to
    5·1 answer
  • For any element in keysList with a value greater than 50, print the corresponding value in itemsList, followed by a space. Ex: I
    8·1 answer
  • The series of events that make up a story is called
    6·2 answers
  • Three variables, x, y and z, supposedly hold strings of digits, suitable for converting to integers. Write code that converts th
    13·2 answers
  • PLEASE HELP! I'm offering brainliest!
    6·1 answer
  • How do you know if something is in the public domain
    5·1 answer
  • PERGUNTA 1
    15·1 answer
  • 1 There are several applications to assist you to surf through the internet, mention
    13·1 answer
  • What's wrong with these codes in code HS Karel challenges(7.1.2. Racing Karel) Codes: //Below is the program that have Karel mov
    13·1 answer
  • TCP and the User Datagram Protocol (UDP) provide _________ between processes on any two of those hosts. A. address translation B
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!