Write a program that reads a web address (for instance, www.yahoo.com) from the keyboard and outputs whether this web address is for a government, a university, a business, a non-profit organization, or another entity.
● If the web address ends with gov, it is a government web address.
● If the web address ends with edu, it is a university web address.
● If the web address ends with com, it is a business web address.
● If the web address ends with org, it is a non-profit organization’s web address.
Otherwise, it is a web address for another entity
import java.util.Scanner;
public class Www {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.print("Enter a web address (for instance, www.yahoo.com): ");
String web=scan.nextLine();
if(web.contains("gov")){
System.out.println("It is a government web address.");
}
else if(web.contains("edu")){
System.out.println("It is a university web address.");
}
else if(web.contains("com")){
System.out.println("It is a business web address.");
}
else if(web.contains("org")){
System.out.println("It is a non-profit organization’s web address.");
}
else {
System.out.println("It is a web address for another entity.");
}
}
}
Comments
Leave a comment