Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class URLParser {
  4.     public static void main(String[] args) {
  5.         Scanner in = new Scanner(System.in);
  6.         String url = in.nextLine();
  7.         String protocol = "";
  8.         String server = "";
  9.         String resource = "";
  10.  
  11.         if (url.split("://").length > 1) {
  12.             protocol = url.split("://")[0];
  13.             url = url.split("://")[1];
  14.         }
  15.         server = url.split("/")[0];
  16.         if (url.split("/").length > 1) {
  17.             resource = url.substring(url.indexOf("/") + 1);
  18.         }
  19.         System.out.println("[protocol] = \"" + protocol + "\"");
  20.         System.out.println("[server] = \"" + server + "\"");
  21.         System.out.println("[resource] = \"" + resource + "\"");
  22.  
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement