歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Java中的main函數

Java中的main函數

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

[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. }
Copyright © Linux教程網 All Rights Reserved