》題目要求
》》隨機輸入一個網址
》》截取出該網址的域名並顯示
》程序實現

1 package cn.fury.test;
2
3 import java.util.Scanner;
4
5 public class Test{
6 public static void main(String[] args) {
7 Scanner sc = new Scanner(System.in);
8 System.out.println("Please input a Uniform Resource Locator:");
9 String URL = sc.nextLine();
10 int start = URL.indexOf('.');
11 int end = URL.indexOf('.',start + 1);
12 String domain_name = URL.substring(start + 1, end);
13 System.out.println("The domain name of the URL inputted by you is:" + domain_name);
14 }
15 }
View Code
》程序升級
》》假設已經有一批網址可供選擇
》》隨機挑選其中的一個網址,求出其域名並顯示
》》notice:該程序員比較懶,持續更新中......