Java中的main函数


Java中的main函数:
  1. package com.han;  
  2.   
  3. public class HanTest {  
  4.     public static void main(String[] args){  
  5.         if(args==null){  
  6.             throw new NullPointerException("The input is \"null\"");  
  7.         }else if((args.length!=1&&args.length!=2)){  
  8.             Throwable cause=new Throwable("You have to input 1 or 2 String arguments");  
  9.             throw new IllegalArgumentException("Wrong numbers of args",cause);  
  10.             //throw new IllegalArgumentException("Wrong numbers of args");   
  11.         }else if(args.length==1){  
  12.             System.out.println(args[0]);  
  13.         }else if(args.length==2){  
  14.             System.out.println(args[0]);  
  15.             System.out.println(args[1]);  
  16.         }  
  17.     }  
  18. }  

 [java]

  1. package com.han;  
  2. public class HanTest2 {  
  3.     public static void main(String[] args){  
  4.         String[] input={"han"};  
  5.         //HanTest.main(null);   
  6.         HanTest.main(input);  
  7.     }  
  8. }  

相关内容