MINtech
Thursday, 30 November 2023
Wednesday, 29 November 2023
Friday, 3 November 2023
Wednesday, 25 October 2023
Reversing the given string
We are going to develop a function that will reverse the given string while preserving the positions of capital letters and punctuation marks and spaces For example ---Input :
MINtech is the bestOutput :
tsebeht si hce tNIM
Lets get started
- /* now we are going to create a function that will
- reverse the given string whithout touching the
- positions of capital letters . and punctuation marks */
- import java.util.* ;
- public class MINtech{
- // Define a static method named "MINtechJAVA" which takes a string as input
- public static String MINtechJAVA(String str){
- // Convert the input string to a character array
- char[] arr = str.toCharArray() ;
- // Initialize two pointers, "left" and "right", to reverse the string
- int left = 0 ;
- int right = arr.length -1 ;
- // Start a loop that continues until "left" is less than "right"
- while(left < right){
- // Move the "left" pointer to the right while it's not a letter
- while(left < right && !Character.isLetter(arr[left])){
- left++ ;
- }
- // Move the "right" pointer to the left while it's not a letter
- while(left < right && !Character.isLetter(arr[right])){
- right -- ;
- }
- // Swap the characters at the "left" and "right" positions
- char temp = arr[left] ;
- arr[left] = arr[right] ;
- arr[right] = temp ;
- // Move the pointers inward
- right -- ;
- left ++ ;
- }
- // Convert the character array back to a string and return it
- return new String(arr) ;
- }
- // Main method to execute the program
- public static void main(String[] args) {
- // Create a Scanner object to read user input
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter a string that you want to reverse : ");
- // Read a line of input from the user
- String str = sc.nextLine();
- // Call the "MINtechJAVA" function and print the reversed string
- System.out.println(MINtechJAVA(str));
- }
- }
Output
Enter a string that you want to reverse : MINtech is amzing gnizmas ih cetNIM Enter a string that you want to reverse : I Love MINtech h cetN IMevoLI https://www.toprevenuegate.com/rzm38ght?key=d841e7a69b77ba94bcb8e38c0573aab0
Friday, 20 October 2023
Time format coneversion from 12H to 24H
You have been given a time in 12 Hours AM/Pm format . And we have convert the given time into 24 Hour (military) format . For exmaple : -- 12:00:00 AM -----------> 00:00:00 01:00:00 PM -----------> 13:00:00 06:56:59 PM -----------> 18:56:59
Lets get started
- import java.util.* ;
- import java.text.* ;
- public class MINtech{
- public static String MINtechJava(String time) {
- try {
- SimpleDateFormat originalFormat = new SimpleDateFormat("hh:mm:ss a");
- SimpleDateFormat targetFormat = new SimpleDateFormat("HH:mm:ss");
- Date date = originalFormat.parse(time) ;
- return targetFormat.format(date) ;
- } catch(Exception e) {
- return "invalid input format" ;
- }
- }
- public static void main (String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter your in hh:mm:ss AM/PM");
- String time = sc.nextLine() ;
- System.out.println( MINtechJava(time));
- }
- }
Output
Enter your in hh:mm:ss AM/PM 6:45:45 PM 18:45:45 Enter your in hh:mm:ss AM/PM 9:9:53 AM 09:09:53 Enter your in hh:mm:ss AM/PM 2:98:78 PM 15:39:18
Subscribe to:
Posts (Atom)