Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

if i am doing a switch statement and I inputted an address of a web, my program

ID: 3528301 • Letter: I

Question

if i am doing a switch statement and I inputted an address of a web, my program is compiling but not looking at the last part .... I want it to look at the gov word or edu word but it just kept on giving me wrong website...here is my program public class Webadd { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("enter address"); String address = scan.next(); switch(address) { case "1": address = "gov"; System.out.println("gov site"); break; case "2": address = "edu"; System.out.println("univ site"); break; default: System.out.println("wrong website"); } } }

Explanation / Answer

/*100% working code*/

import java.util.Scanner;

public class Webadd {

public enum domainName {
gov, edu
};

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);
System.out.println("enter address");
String address = scan.next();
String[] strAdd = address.split("\.");
try {
switch (domainName.valueOf(strAdd[2])) {
case gov:
System.out.println("gov site");
break;
case edu:
System.out.println("univ site");
break;
default:
System.out.println("wrong website");
}

} catch (Exception e) {
System.out.println("wrong website");
}
}
}