Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class _02_Parse_URL {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- // "https://www.facebook.com/"
- String[] input = scan.nextLine().split("://");
- if (input.length == 2) {
- System.out.printf("Protocol = %s\n", input[0]);
- String[] dsda = input[1].split("/");
- if (dsda.length >= 2) {
- System.out.printf("Server = %s\n", dsda[0]);
- System.out.printf("Resources = ");
- for (int i = 1; i < dsda.length; i++) {
- if (i != dsda.length - 1) {
- System.out.printf("%s/", dsda[i]);
- }
- else {
- System.out.printf("%s", dsda[i]);
- }
- }
- }
- else {
- System.out.printf("Invalid URL\n");
- }
- }
- else {
- System.out.printf("Invalid URL\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement