Q:

How to execute alphanumaric string in java

When I give CS1001  as an input the output has to show a valid message. Apart from that every input must be invalid. I don't understand what logic I have to apply for it?
import java.util.Scanner;

public class EmployeeInfo {
    private static final String CSXXX = "";

    public void empCheck(String empId) throws InvalidEmployeeException {
        if (!CSXXX.equals(empId))
            throw new InvalidEmployeeException("Employee ID inValid");
        else
            System.out.println("Employee ID is Valid");

    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("Main Starts....");
        EmployeeInfo ei = new EmployeeInfo();
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter Employee ID");
        String w = sc.nextLine();
        try {
            ei.empCheck(w);
        } catch (InvalidEmployeeException iee) {
            System.out.println(iee);
        }
        System.out.println("Main End...");
    }
}

InvalidEmployeeException.java
public class InvalidEmployeeException extends Exception {
    public InvalidEmployeeException(String s) {
        // TODO Auto-generated constructor stub
        super(s);
    }
}

A:

 import java.util.Scanner;

public class EmployeeInfo {

    String Str = "CS";

    public void empCheck(String empId) throws InvalidEmployeeException {

        if (!empId.startsWith(Str)) 

            // if (!CSXXX.equals(empId))
            throw new InvalidEmployeeException("Employee ID is inValid");
        else
            System.out.println("Employee ID is Valid");

    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("Main Starts....");
        EmployeeInfo ei = new EmployeeInfo();
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter Employee ID");
        String w = sc.nextLine();

        try {
            ei.empCheck(w);
        } catch (InvalidEmployeeException iee) {
            System.out.println(iee);
        }
        System.out.println("Main End...");
    }

}

