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 your biology class, you will be giving a presentation of the findings of a plant
kaheart [24]

Answer:

PowerPoint

Explanation:

It is dedicated for presentation.

5 0
3 years ago
Read 2 more answers
Which sql server 2012 edition is targeted at hosted, internet-facing deployment?
Mice21 [21]
<span>The Web version will work for this type of need. This version runs at a slightly lesser capability than the full version, but will still perform many of the advanced functions of SQL Server. The processor and RAM utilizations are a bit less than the maximum provided in other versions.</span>
7 0
3 years ago
Disadavantage of using internet?​
skad [1K]

Answer:

Radiation from the screens will damage your brain and kill brain cells.

The lights dry out your eyes and you blink a lot more.

Explanation:

5 0
2 years ago
Read 2 more answers
WILL GIVE BRAINLIEST!!!!!
egoroff_w [7]
Third law :) Hope this helped you
5 0
3 years ago
Read 2 more answers
Qual foi o primeiro computador no mundo a ser criado e qual é a hitória por trás?
Bess [88]

Answer:

Espero que isso ajude você!

Explanation:

O ENIAC foi inventado por J. Presper Eckert e John Mauchly na Universidade da Pensilvânia e começou a construção em 1943 e só foi concluído em 1946. Ocupava cerca de 1.800 pés quadrados e usava cerca de 18.000 tubos de vácuo, pesando quase 50 toneladas.

4 0
3 years ago
Other questions:
  • What is output by the following?<br><br>print (type("95"))
    13·1 answer
  • What is the acronym that helps you remember the order of math operations?
    9·2 answers
  • The expression that is tested by a switch statement must have a(n) __________ value.
    12·1 answer
  • What lets you do many things, like write book reports and stories?
    15·1 answer
  • Which section of a personal narritive requires the most development?
    14·1 answer
  • Python;
    6·1 answer
  • What is the purpose of a hyperlink in a presentation?
    11·1 answer
  • Who has played pokemon red, blue, or yellow on the gameboy
    9·2 answers
  • Can someone plss help me!!
    5·1 answer
  • How to create drop down list in excel with multiple selections.
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!