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
________ tells users how to use software and what to do if software problems occur.
vitfil [10]

Answer:

Documentation tells users how to use software and what to do if software problems occur.

Explanation:

Documents and Standard Operating Procedures (SOPs) help users use the software that they want to use. This is an advantage to whoever is selling the software so that they don't receive customer complaints and people continue to buy their product.

4 0
1 year ago
In the second example with modulus math, why can't Eve find the solution?
Leno4ka [110]
C. She would have to resort to trial and errors to find a matching exponent
6 0
2 years ago
Which of the following is an example of an application software?
pishuonlain [190]
Word processing software
6 0
2 years ago
Recording relative positions should reduce total programming time true or false
Svet_ta [14]

This is true. Recording relative positions in most cases will reduce total programming time and make it over all more efficient.

4 0
3 years ago
What property do we use to distinguish a specific element from a form? value name click this
Andrews [41]
<span>If you match the physical properties of a substance you dont know about to the properties of a known substance, you now know what you've got. For example, if you know that compound X is bright yellow and screams when you poke it, an unknown sample that is yellow and screams that you poke it is probably compound X. trust me, im a dog in a suit.</span>
7 0
3 years ago
Other questions:
  • The world wide web was originally conceived of as a(n) _____.
    14·1 answer
  • Why is it important to not get distracted while driving?
    13·2 answers
  • To close the ____ view, click File on the Ribbon or click the preview of the document in the Info gallery to return to the docum
    9·1 answer
  • What was the process called that required the photographer to have a tent or darkroom handy so that chemicals could be mixed qui
    7·1 answer
  • Which term describes the distance from one point on a wave to the same point on the next wave?
    13·2 answers
  • Ineeedd help please 35 points question
    5·1 answer
  • What is tnylnk? I keep seeing people leave answers with this.....can someone explain what this is, please...I might give brainie
    6·2 answers
  • Match the desired outcome to the appropriate action.
    6·1 answer
  • The term Linux Intrusion Detection System ( LIDS) refers to a command that allows an administrator to run processes as root with
    5·1 answer
  • READ CAREFULLY! There is a difference between moving and copying files.a. Create a directory named . For example, mine would be
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!