time conversion solution
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:
- how to count the number of occurrences of an element in a arraylist in java
- java get icon for file type
- java save string in text file
- java loop through object
- loop collection android
- log4j with spring boot restful services
- java change boolean to opposite
- abs in java
- java get int from double without rounding
- cosinus-1 java
- BoxLayout java
- print hello world in java
- java int stream min
- map with insertion order preserved java
- how to make a char uppercase in java
- python to java converter
- java 8 collect multiple lists into single list
- how to make int array java android
- variable cannot be dereferenced java
- android studio keep device awake
- how to import an arraylist in java
- java how to read a text file
- java quit application
- padding a string with 0 in java