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
PLZ HELP!!!
mariarad [96]
Answer: A. Usability testing
Explanation:
Usability testing would be the correct answer because if the user interface isn't "frendly" then people won't be able to use it properly. Or if you are refering to the word friendly as looking safe, then even more so would be usability testing. Because if people don't like the fonts and styles of the user interface, they might not use it at all.
8 0
2 years ago
Please help me with these short questions >..
Thepotemich [5.8K]

Answer:

bmjcmbbobnkpkkjkbk

Explanation:

vuvkopbbkvkhovjlplbkp

6 0
2 years ago
The __________ energy in food is changed into mechanical energy by your muscles.
qwelly [4]
The chemical energy in food is transformed into mechanical energy through a process called respiration. This isn't really a computers and technology question though. Try Biology next time.
4 0
2 years ago
The _______ number system allows digital devices to represent virtually any number simply by using 0s and 1s.â
zhuklara [117]
The answer is <span>Digital data 

</span>
4 0
3 years ago
The advantage of an electronic ____ is that the content can be easily edited and updated to reflect changing financial condition
Lana71 [14]
Computer.................................
6 0
3 years ago
Other questions:
  • Simplify (6x+6)+(-3-4x) please hurry!!!!!
    6·1 answer
  • Gini is a manager at a website design firm. She has a timeline prepared for the product to be delivered to the client. She needs
    6·2 answers
  • Design and implement an application that plays the Hi-Lo guessing game with numbers. The program should pick a random number bet
    13·1 answer
  • What is the unit used to describe the intensity of sound?
    5·1 answer
  • What are some characteristics of pseudocode? Check all that apply. Pseudocode is an informal way of expressing ideas and algorit
    11·2 answers
  • When a computer is suffering from a virus, you can use a compiler to help remove the virus. True or false?
    13·1 answer
  • Which of the following defines a computer program?
    14·1 answer
  • Reading (BCK FORM 2C IT 2020-2021)
    12·2 answers
  • Write at least 4 sentences
    9·1 answer
  • Read-only memory chips are used to
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!