Bắt đầu ngayBắt đầu miễn phí

Domain checking

You are planning your summer vacation and need to secure some permits. So you want to make sure that a site is from the US government to be sure of its legitimacy. You've been told they all use the ".gov" domain, and that only government sites can use it.

Bài tập này là một phần của khóa học

Intermediate Java

Xem khóa học

Hướng dẫn bài tập

  • Check that the given url contains ".gov" as a substring. Use the variable toFind to do that.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

class DomainChecker {
  public static void main(String[] args) {
    String toFind = ".gov";
    String url = "https://www.usa.gov/holidays";

    // Use the right function to check if our url contains the .gov domain
    System.out.println(url.____(toFind));
  }
}
Chỉnh sửa và Chạy Mã