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
Omar sends a PDF file to his teacher. He then prepares another copy of the presentation that includes only the slides he wants t
maria [59]

Answer:

D. Custom Slide Show

Explanation:

Correct on edg

7 0
3 years ago
A web browser sends a request to the web server using what
goldenfox [79]
Web browsers and servers communicate via TCP/IP.  HTTP protocol is the standard application protocol that supports the responses.
3 0
3 years ago
_____ is a group of Internet-based applications that build on the ideological and technological foundations of Web 2.0, and that
lutik1710 [3]

Answer: Social media

Explanation:

 Social media is defined as the group of the internet based various applications that basically build on the foundation of  technological and ideological of the web 2.0. It basically allow the exchange of the user content and creation.

It is the most flexible platform that enable the users with the huge experience. It is also known as free and open source platform. It basically contain the various content that are algorithm driven and machine learning.

 

3 0
3 years ago
How do you change a automatic transmission
irinina [24]

Answer:

ohhh ok to all transactions.

6 0
3 years ago
Based on its location in the periodic table, we know that ALL BUT one property applies to the element radon. Which property does
blsea [12.9K]
Radon is not synthetic! It is produced naturally by the decay of uranium and radium. Radon is used in treating cancer - it is radioactive, nonreactive and a gas at room temperature.
6 0
4 years ago
Read 2 more answers
Other questions:
  • Using information from the lesson, explain how new technologies change your experience as a consumer.
    5·2 answers
  • When planning the structure of a spreadsheet, columns are for _______ items and rows are for _______ items.
    5·2 answers
  • How to connect an Apple Watch series 3 to your iPhone (ASAP)
    6·2 answers
  • Why will my note 5 not download videos from the web?
    14·1 answer
  • 6. Which is not considered a storage device a. USB Flash Drive b. External hard Drive c. MS-Windows d. Internal Hard Drive e. Me
    11·1 answer
  • Write a program that keeps track of a simple inventory for a store. While there are still items left in the inventory, ask the u
    12·2 answers
  • How many cost units are spent in the entire process of performing 40 consecutive append operations on an empty array which start
    14·1 answer
  • Create One print command in LOGO​
    12·1 answer
  • When proofreading, you should do all of the following except _____.
    14·1 answer
  • How does a fully integrated Data and Analytics Platform enable organizations to convert data into consumable information and ins
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!