From 1779e0d656f10493b9c71e1281329d728ba7921a Mon Sep 17 00:00:00 2001 From: Avishkar21 Date: Sat, 3 Oct 2020 04:27:34 +0530 Subject: [PATCH 1/2] Added time conversion program --- Convert12HourClockTo24Hour.java | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Convert12HourClockTo24Hour.java diff --git a/Convert12HourClockTo24Hour.java b/Convert12HourClockTo24Hour.java new file mode 100644 index 0000000..3d304be --- /dev/null +++ b/Convert12HourClockTo24Hour.java @@ -0,0 +1,45 @@ +import java.io.*; +import java.math.*; +import java.text.*; +import java.util.*; +import java.util.regex.*; + +public class TimeConversion { + //This function will convert AM or PM based time to a 24 hour based time + //Sample input 06:09:34PM --> Sample output 18:09:34 + static String timeConversion(String s) { + String unit = Character.toString(s.charAt(s.length()-2))+ + Character.toString(s.charAt(s.length()-1)); + int len = s.length(); + s = s.replace("AM", ""); + s = s.replace("PM", ""); + int hour = Integer.parseInt(Character.toString(s.charAt(0))+ + Character.toString(s.charAt(1))); + + if(unit.equals("AM") && hour==12) + { + hour = hour-12; + } + else if(unit.equals("PM") && hour != 12) + hour = hour+12; + + + StringBuilder result = new StringBuilder(s); + result.setCharAt(0, (char)((hour/10)+'0')); + result.setCharAt(1, (char)((hour%10)+'0')); + + //System.out.print("Unit "+unit+" Hour "+hour+ " Result "+(char)(hour%10)); + return result.toString(); + } + + private static final Scanner scan = new Scanner(System.in); + + public static void main(String[] args) throws IOException { + Scanner scan = new Scanner(System.in); + String s = scan.nextLine(); + + String result = timeConversion(s); + + System.out.println(result); + } +} From 531865080caf151b66f229c603b3939b97cbfac4 Mon Sep 17 00:00:00 2001 From: Avishkar21 Date: Sat, 3 Oct 2020 04:39:03 +0530 Subject: [PATCH 2/2] Added a program to rotate the array by k steps and print the specific indexes given at runtime --- CircularArrayRotation.java | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 CircularArrayRotation.java diff --git a/CircularArrayRotation.java b/CircularArrayRotation.java new file mode 100644 index 0000000..833aec1 --- /dev/null +++ b/CircularArrayRotation.java @@ -0,0 +1,73 @@ +import java.io.*; +import java.math.*; +import java.security.*; +import java.text.*; +import java.util.*; +import java.util.concurrent.*; +import java.util.regex.*; + +public class Solution { + + // This function rotates the array by k steps and then print the values + // of indexes stores in queries array. + static int[] circularArrayRotation(int[] a, int k, int[] queries) { + int res[]=new int[queries.length]; + k=k%a.length; + for(int i=0; i