Wednesday, 17 April 2024

Extracting information from URL

Input URL format:


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // Reading input URL
        String url = scanner.nextLine().trim();

        // Extracting parameters and their values
        String[] parts = url.split("\\?");
        String[] params = parts[1].split("&");

        // Printing parameters and their values
        for (String param : params) {
            String[] keyValue = param.split("=");
            System.out.println(keyValue[0] + ": " + keyValue[1]);
        }
    }
}

No comments:

Post a Comment

Good thoughtful question on Binary search on answers

Problem link:  https://leetcode.com/problems/maximize-score-of-numbers-in-ranges/description/ Solution: //import java.util.Arrays; class So...