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 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); + } +} diff --git a/ConvertTimeInWords.java b/ConvertTimeInWords.java new file mode 100644 index 0000000..e998558 --- /dev/null +++ b/ConvertTimeInWords.java @@ -0,0 +1,76 @@ +import java.io.*; +import java.util.*; +import java.text.*; +import java.math.*; +import java.util.regex.*; + +public class MyClass { + + public static void main(String[] args) { + //This program will take numerical inputs for hour and minutes, after that + //based on these values it will convert the numerical time to time in words. + //Example: Sample input : 06:15 --> Sample output : quatrter past six + String[] numberWords = new String[] { + "", + "one", + "two", + "three", + "four", + "five", + "six", + "seven", + "eight", + "nine", + "ten", + "eleven", + "twelve", + "thirteen", + "fourteen", + "fifteen", + "sixteen", + "seventeen", + "eighteen", + "nineteen", + "twenty", + "twenty one", + "twenty two", + "twenty three", + "twenty four", + "twenty five", + "twenty six", + "twenty seven", + "twenty eight", + "twenty nine" + }; + + Scanner in = new Scanner(System.in); + int hour = in.nextInt(); + int minute = in.nextInt(); + + int nextHour = (hour % 12) + 1; + + if(minute == 0) { + System.out.printf("%s o' clock\n", numberWords[hour]); + } + + else if(minute == 15) { + System.out.printf("quarter past %s\n", numberWords[hour]); + } + + else if(minute == 30) { + System.out.printf("half past %s\n", numberWords[hour]); + } + + else if(minute == 45) { + System.out.printf("quarter to %s\n", numberWords[nextHour]); + } + + else if(minute < 30) { + System.out.printf("%s minutes past %s\n", numberWords[minute], numberWords[hour]); + } + + else { + System.out.printf("%s minutes to %s\n", numberWords[60 - minute], numberWords[nextHour]); + } + } +} \ No newline at end of file