time conversion solution
Java
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;
public class Solution {
static String timeConversion(String s)
{
String[] arr = s.split(":"); // this will split the String s in array arr=[hh,mm,ssPM]
String h=arr[0];
String meridiem=arr[2].substring(2,4);
if(meridiem.equals("PM"))
{
if(!h.equals("12"))
{
int h1 = Integer.parseInt(h);
h1=h1+12;
h=""+h1;
}
}
else
{
if(h.equals("12"))
{
h="00";
}
}
return h + ":" + arr[1] + ":" + arr[2].substring(0,2);
}
private static final Scanner scan = new Scanner(System.in);
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
String s = scan.nextLine();
String result = timeConversion(s);
bw.write(result);
bw.newLine();
bw.close();
}
}
Also in Java:
- Title
- shorthand if java without else
- Category
- Java
- Title
- priority queue java reverse order
- Category
- Java
- Title
- java string copy characters
- Category
- Java
- Title
- iterate through hashtable java
- Category
- Java
- Title
- iterator loop java
- Category
- Java
- Title
- how to find substring in java
- Category
- Java
- Title
- create jdbc connection in java
- Category
- Java
- Title
- raise number to power java
- Category
- Java
- Title
- how to make one java class inherit from another
- Category
- Java
- Title
- date to string java
- Category
- Java
- Title
- how to add integers in java
- Category
- Java
- Title
- reverse array in java
- Category
- Java
- Title
- java animated gif example
- Category
- Java
- Title
- input java
- Category
- Java
- Title
- convert int array to integer list java
- Category
- Java
- Title
- java call another constructor
- Category
- Java
- Title
- scan a string using scanner class in java
- Category
- Java
- Title
- java file exists
- Category
- Java
- Title
- java bigdecimal compareto
- Category
- Java
- Title
- java observable
- Category
- Java
- Title
- java for
- Category
- Java
- Title
- selection sort in java
- Category
- Java
- Title
- processing play sound
- Category
- Java
- Title
- java scanner next()
- Category
- Java
- Title
- java public private key encryption
- Category
- Java
- Title
- sort array java
- Category
- Java
- Title
- converting char array to string
- Category
- Java
- Title
- java read file from command line argument
- Category
- Java
- Title
- java packages example
- Category
- Java
- Title
- java script to detect the crome browser
- Category
- Java
- Title
- socket in java
- Category
- Java
- Title
- java last element in array
- Category
- Java
- Title
- java min function
- Category
- Java
- Title
- queue implementation in java using arraylist
- Category
- Java
- Title
- java recursion
- Category
- Java
- Title
- how to reverse a list in java
- Category
- Java
- Title
- discord jda remove @everyone from channel
- Category
- Java
- Title
- how to write sensor data into file android studio
- Category
- Java
- Title
- how make a final variable in java
- Category
- Java
- Title
- inline foreach java
- Category
- Java
- Title
- java code to get all leaf nodes of a xml file
- Category
- Java
- Title
- java method
- Category
- Java
- Title
- java how to read a text file
- Category
- Java
- Title
- arraylist in java
- Category
- Java
- Title
- exponents java
- Category
- Java
- Title
- scanner check if int
- Category
- Java
- Title
- array of objects in java
- Category
- Java
- Title
- 3-way radix quicksort java
- Category
- Java
- Title
- convert string to mayus java
- Category
- Java
- Title
- java 8 find min value in array
- Category
- Java
- Title
- set iteration java
- Category
- Java
- Title
- convert char to string java
- Category
- Java
- Title
- java 8 validate based on pair of strings
- Category
- Java
- Title
- how to print to the console in java
- Category
- Java
- Title
- java loop through string
- Category
- Java
- Title
- java boolean even number
- Category
- Java
- Title
- java new string with values
- Category
- Java
- Title
- how to exit a for loop in java
- Category
- Java
- Title
- java quit application
- Category
- Java
- Title
- random java
- Category
- Java
- Title
- convert java list to array
- Category
- Java
- Title
- non primitive data types in java
- Category
- Java
- Title
- java methods
- Category
- Java
- Title
- how to make a pre set list java
- Category
- Java
- Title
- editer un label java
- Category
- Java
- Title
- scanner in java
- Category
- Java
- Title
- java read lines from file
- Category
- Java
- Title
- how lock horizontal orientation android
- Category
- Java
- Title
- how to make an arraylist java
- Category
- Java
- Title
- how to make a variable unchangeable in java
- Category
- Java
- Title
- bracket balancing program in java
- Category
- Java
- Title
- removeeventlistener
- Category
- Java
- Title
- initialize arraylist
- Category
- Java
- Title
- java create txt file
- Category
- Java
- Title
- how to change the color of a menubar in java
- Category
- Java
- Title
- mutable string in java
- Category
- Java
- Title
- JavaFX mouse over effe
- Category
- Java
- Title
- String array into LinkedList java
- Category
- Java
- Title
- java get command line input
- Category
- Java
- Title
- write an infinite loop java
- Category
- Java
- Title
- java 8 list stream delete by name
- Category
- Java
- Title
- how get started with LWJGL 3
- Category
- Java
- Title
- basic java coding
- Category
- Java
- Title
- how to make a searchable list in java
- Category
- Java
- Title
- java setroundingmode
- Category
- Java
- Title
- java foreach
- Category
- Java
- Title
- android cardview dependency
- Category
- Java
- Title
- Java array equals
- Category
- Java
- Title
- public static void main(string args)
- Category
- Java
- Title
- programa que convierete un archi de c a java
- Category
- Java
- Title
- main method java
- Category
- Java
- Title
- how to get a user to add to an arraylist in java
- Category
- Java
- Title
- java linked list functions
- Category
- Java
- Title
- how to read in a file in java
- Category
- Java
- Title
- recursive function for fibonacci series in java javascript
- Category
- Java
- Title
- snackbar not showing with bottom nav
- Category
- Java
- Title
- capitalize string java
- Category
- Java
- Title
- checking if a given integer is a prime number java
- Category
- Java
- Title
- java vector push_back
- Category
- Java
- Title
- how to create an action listener in java
- Category
- Java