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
The expression 10,785(1.0275)x represents the amount of money in an investment account with interest that compounds annually for
Kamila [148]

E

According to the question,

The amount of investment money is $10,785 and the rate of interest is 1.0275%. The amount of money will be multiplied with the rate of interest and the year.

To get future value of the investment it will be like

FV = PV(1+i)x

Therefore , Future value = 10,785(1.0275)x

8 0
3 years ago
Read 2 more answers
Ryan needs to see the space available to insert content on a slide in his presentation. Which feature of a presentation program
MariettaO [177]

Answer:

Layout

Explanation:

answer exists on

brainly.com/question/3749015

5 0
3 years ago
Mrs. Zoo gave out the rubric for our essay. She stated that our essay should be complete by Friday of that week. I didn't have t
Rom4ik [11]

Answer:

No

Explanation:

You had the whole week for the essay but didn't do it and then turned it in late.

6 0
3 years ago
What is a recent technological breakthrough with an impact that can be compared to the invention of paper nearly 2,000 years ago
Evgesh-ka [11]
<span>Electronic communication</span>
3 0
3 years ago
You have installed a new sound card in your system, closed the computer case, and turned on the computer. Windows boots and you
ArbitrLikvidat [17]

The most likely problem which led to the lack of sound after the installation of the new sound card is that the '<em>sound card is not recognized or incompatible</em> '

  • The sound card is an hardware which is installed into a computer in other to allow the the system produce audio signal.

  • Without a sound card installed into a computer, then such computer would not be able to perform <em>audio</em> <em>input or produce audio signals</em>.

However, when a sound card is present and, the computer fails to produce audio signal, then the most likely problem is that, the <em>sound card installed isn't recognized</em>.

Learn more :brainly.com/question/25055825

8 0
2 years ago
Other questions:
  • Think of a game you are familiar with and identify at least three team responsibilities which were required to make the game, on
    5·1 answer
  • The tone a writer takes is referred to as the writing _____.
    7·2 answers
  • HELP I don't understand this
    14·2 answers
  • A typist is entering text on keyboard at the rate of 30 words per minute. if each word is 6 characters long on average, what ban
    5·2 answers
  • In this challenge, write a function to add two floating point numbers. Determine the integer floor of the sum. The floor is the
    8·1 answer
  • Most hard drives are divided into sectors of 512 bytes each. Our disk has a size of 16 GB. Fill in the blank to calculate how ma
    9·1 answer
  • What methods would you add to make this class declarationvery useful?
    11·2 answers
  • Creation of ____________will help you to study the behavior of the real system
    11·1 answer
  • What maintains data about various types of objects, events, people, and places?
    10·1 answer
  • The _____ layer addresses how the software will execute on specific computers and networks.
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!