Question: May you fix what's wrong with this Java code? It's not compiling correctly and gives me an error code. public class DomainNameTest.java { // drive

May you fix what's wrong with this Java code? It's not compiling correctly and gives me an error code.

public class DomainNameTest.java { // drive code public static void main (String args[]) { Scanner sc = new Scanner (System.in); System.out.print ("Enter the domain name : "); String domainName = sc.next (); // user input // check domain name is valid or invalid if (isValidDomainName (domainName)) { domainName = "www." + domainName + ".com"; System.out.println ("It is valid Domain Name: " + domainName); } else { System.out.println ("It is invalid Domain Name."); } }

// isValidDomainName() is Function to validate domain name. // International domain names maximum charcater b 63 characters and minimum b 3 characters //Only alphanumeric characters and hyphens are allowed. The name cannot start or end in a hyphen.*/ public static boolean isValidDomainName (String domainName) { // check condition for International domain names maximum charcater 63 characters and minimum 3 characters if (domainName.length () < 3 || domainName.length () > 63) return false;

// check condition for "domain name cannot start or end in a hyphen". if (domainName.charAt (0) == '-' || domainName.charAt (domainName.length () - 1) == '-') return false;

// check the condition for domain name "Only alphanumeric characters and hyphens are allowed" for (int i = 0; i < domainName.length (); i++) { if ((domainName.charAt (i) >= 'a' && domainName.charAt (i) <= 'z') || (domainName.charAt (i) >= 'A' && domainName.charAt (i) <= 'Z') || (domainName.charAt (i) >= '0' && domainName.charAt (i) <= '9') || (domainName.charAt (i) == '-')) continue; else return false; }

// if all condition are ture then return true . return true; } }

-Thanks and May you keep in Java for beginners?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!