Thursday, 30 November 2023

JAVA

Roman To Numbers



Lets get started

Java code :--

 
         
  1. import java.util.HashMap;
  2. import java.util.Map;
  3. import java.util.Scanner;
  4. public class MINtech {
  5. // Function to convert a Roman numeral to an integer
  6. public static int romanToInt(String s) {
  7. // Create a map to store the values of Roman numerals
  8. Map romanMap = new HashMap<>();
  9. romanMap.put('I', 1);
  10. romanMap.put('V', 5);
  11. romanMap.put('X', 10);
  12. romanMap.put('L', 50);
  13. romanMap.put('C', 100);
  14. romanMap.put('D', 500);
  15. romanMap.put('M', 1000);
  16. // Initialize variables to store the result and the previous value
  17. int result = 0;
  18. int prevValue = 0;
  19. // Iterate through the Roman numeral from right to left
  20. for (int i = s.length() - 1; i >= 0; i--) {
  21. // Get the numeric value of the current Roman numeral character
  22. int value = (int) romanMap.get(s.charAt(i));
  23. // Check if the current value is less than the previous value
  24. if (value < prevValue) {
  25. // If yes, subtract the current value from the result
  26. result -= value;
  27. } else {
  28. // If no, add the current value to the result
  29. result += value;
  30. }
  31. // Update the previous value for the next iteration
  32. prevValue = value;
  33. }
  34. // Return the final result
  35. return result;
  36. }
  37. public static void main(String[] args) {
  38. // Create a scanner to take user input
  39. Scanner scanner = new Scanner(System.in);
  40. // Get user input for a Roman numeral
  41. System.out.print("Enter a Roman numeral: ");
  42. String userInputRoman = scanner.nextLine();
  43. // Convert Roman numeral to integer and print the result
  44. int integerResult = romanToInt(userInputRoman);
  45. System.out.println("Integer: " + integerResult);
  46. // Close the scanner to avoid resource leaks
  47. scanner.close();
  48. }
  49. }

Output




Python code :---

Output

Wednesday, 29 November 2023

JAVA

Longest substring without repeating characters



Lets get started

Java code :--

Output




Python code :---

Output

JAVA

sort colors



Lets get started

Java code :--

Output




Python code :---

Output

Friday, 3 November 2023

Queue Operations using Stacks

JAVA

Queue Operations



Lets get started

Output

Wednesday, 25 October 2023

JAVA

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 best

Output :

tsebeht si hce tNIM

Lets get started

 
      
  1. /* now we are going to create a function that will
  2. reverse the given string whithout touching the
  3. positions of capital letters . and punctuation marks */
  4. import java.util.* ;
  5. public class MINtech{
  6. // Define a static method named "MINtechJAVA" which takes a string as input
  7. public static String MINtechJAVA(String str){
  8. // Convert the input string to a character array
  9. char[] arr = str.toCharArray() ;
  10. // Initialize two pointers, "left" and "right", to reverse the string
  11. int left = 0 ;
  12. int right = arr.length -1 ;
  13. // Start a loop that continues until "left" is less than "right"
  14. while(left < right){
  15. // Move the "left" pointer to the right while it's not a letter
  16. while(left < right && !Character.isLetter(arr[left])){
  17. left++ ;
  18. }
  19. // Move the "right" pointer to the left while it's not a letter
  20. while(left < right && !Character.isLetter(arr[right])){
  21. right -- ;
  22. }
  23. // Swap the characters at the "left" and "right" positions
  24. char temp = arr[left] ;
  25. arr[left] = arr[right] ;
  26. arr[right] = temp ;
  27. // Move the pointers inward
  28. right -- ;
  29. left ++ ;
  30. }
  31. // Convert the character array back to a string and return it
  32. return new String(arr) ;
  33. }
  34. // Main method to execute the program
  35. public static void main(String[] args) {
  36. // Create a Scanner object to read user input
  37. Scanner sc = new Scanner(System.in);
  38. System.out.println("Enter a string that you want to reverse : ");
  39. // Read a line of input from the user
  40. String str = sc.nextLine();
  41. // Call the "MINtechJAVA" function and print the reversed string
  42. System.out.println(MINtechJAVA(str));
  43. }
  44. }

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
        
https://www.toprevenuegate.com/rzm38ght?key=d841e7a69b77ba94bcb8e38c0573aab0 https://www.toprevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796
https://www.toprevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796
https://www.toprevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796
https://www.toprevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796
https://www.toprevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796

Friday, 20 October 2023

JAVA

Time format coneversion from 12H to 24H

https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796
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
        
https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796

Lets get started

 
      
  1. import java.util.* ;
  2. import java.text.* ;
  3. public class MINtech{
  4. public static String MINtechJava(String time) {
  5. try {
  6. SimpleDateFormat originalFormat = new SimpleDateFormat("hh:mm:ss a");
  7. SimpleDateFormat targetFormat = new SimpleDateFormat("HH:mm:ss");
  8. Date date = originalFormat.parse(time) ;
  9. return targetFormat.format(date) ;
  10. } catch(Exception e) {
  11. return "invalid input format" ;
  12. }
  13. }
  14. public static void main (String[] args) {
  15. Scanner sc = new Scanner(System.in);
  16. System.out.println("Enter your in hh:mm:ss AM/PM");
  17. String time = sc.nextLine() ;
  18. System.out.println( MINtechJava(time));
  19. }
  20. }
https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796 https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796 https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796

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

  
        
https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796
` https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796
` https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796
` https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796
` https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796
` https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796
` https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796https://www.highcpmrevenuegate.com/s4ttwmua2u?key=c02c9252219c2ddb8d72b452016a4796
`