⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exceptionexample.java

📁 这是个简单的Java程序
💻 JAVA
字号:
class NoLowerLetter extends Exception
{
	 public void print()
	    {
	       System.out.printf("%c",'#');
	    }
}
class NoDigit extends Exception
{
	 public void print()
	    {
	       System.out.printf("%c",'*');
	    }
}
class People
{
  void  printLetter(char c) throws NoLowerLetter
   {
      if(c<'a'||c>'z')
        {
    	  NoLowerLetter noLowerLetter=new NoLowerLetter();
    	  throw noLowerLetter;
        }
      else
        {
           System.out.print(c);
        }
   }
  void  printDigit(char c) throws NoDigit
  {
     if(c<'1'||c>'9')
       {
          NoDigit noDigit=new NoDigit();
          throw noDigit;
       }
     else
       {
          System.out.print(c);
       }
  }
}
public class ExceptionExample {
	public static void main (String args[ ])
    {
        People people=new People( );
        for(int i=0;i<128;i++)
           {   
              try
                 {
                   people.printLetter((char)i);
                 }
               catch(NoLowerLetter e)
                 {
                    e.print();
                 }
           }
        for(int i=0;i<128;i++)
           {  
               try
                 {
                   people.printDigit((char)i);
                 }
               catch(NoDigit e)
                 {
                    e.print( );
                 }
           }
	System.out.println("吕素涵 电子04-1 040214132");

     }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -