Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _02_Parse_URL {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.          // "https://www.facebook.com/"
  8.         String[] input = scan.nextLine().split("://");
  9.         if (input.length == 2) {
  10.             System.out.printf("Protocol = %s\n", input[0]);
  11.             String[] dsda = input[1].split("/");
  12.             if (dsda.length >= 2) {
  13.                 System.out.printf("Server = %s\n", dsda[0]);
  14.                 System.out.printf("Resources = ");
  15.                 for (int i = 1; i < dsda.length; i++) {
  16.                     if (i != dsda.length - 1) {
  17.                         System.out.printf("%s/", dsda[i]);
  18.                     }
  19.                     else {
  20.                         System.out.printf("%s", dsda[i]);
  21.                     }
  22.                 }
  23.  
  24.             }
  25.             else {
  26.                 System.out.printf("Invalid URL\n");
  27.             }
  28.         }
  29.         else {
  30.             System.out.printf("Invalid URL\n");
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement