在类InvalidNameException中找不到main(String [])方法

时间:2019-10-11 16:04:51

标签: java

class InvalidNameException extends Exception{}
class Slip11
{
    String nm;
    Slip11(String nm)
    {
        this.nm=nm;
    }
    void display()
    {
        System.out.println("EMPLOYEE NAME : "+nm+" is valid");
    }
    public static void main(String[] args)throws Exception  
    {
        BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
        System.out.println("ENTRE NAME OF EMPLOYEE");
        String name=br.readLine();

        try
        {
            int len=name.length();
            int flag=0;
            for(int i=0;i<len;i++)
            {
                char ch=name.charAt(i);
                if(Character.isLowerCase(ch)|| Character.isUpperCase(ch))
                {
                    flag=1;
                }
                else
                {
                    flag=1;
                    break;
                }
            }
            if(flag==-1)
            {
                throw new InvalidNameException();
            }
            else
            {
                Slip11 s=new Slip11(name);
                s.display();
            }
        }
        catch(InvalidNameException e)
        {
            System.out.println("employee name is not valid "+name+" is  Invalid");
        }
    }
}

0 个答案:

没有答案