?? ex1.java
字號:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package chenchao5;/** * * @author williechen */public class Ex1 { /** * @param args */ private String firstArgs; private int secondArgs; private int thirdArgs; private String result; public static void main(String[] args) { Ex1 test = new Ex1(); try { test.checkArgs(args); System.out.println(test.getResult()); } catch (ArgsException e) { System.out.print(e.toString()); } // TODO 自動生成方法存根 } public String getResult() { result = firstArgs.substring(secondArgs, thirdArgs); return result; } protected void checkArgs(String[] pars) throws ArgsException { if (pars.length != 0) { switch (pars.length) { case 1: throw new ArgsException(ArgsException.exceptions.SECONDLESS); case 2: throw new ArgsException(ArgsException.exceptions.THIRDLESS); case 3: setArgs(pars); break; default: throw new ArgsException(ArgsException.exceptions.NORMAL); } } else { throw new ArgsException(ArgsException.exceptions.FIRSTLESS); } } protected void setArgs(String[] pars) throws ArgsException { firstArgs = pars[0]; try { secondArgs = Integer.parseInt(pars[1]); } catch (Exception e) { throw new ArgsException(ArgsException.exceptions.SECONDTYPEERROR); } try { thirdArgs = Integer.parseInt(pars[2]); } catch (Exception e) { throw new ArgsException(ArgsException.exceptions.THIRDTYPEERROR); } if (secondArgs > firstArgs.length()) { throw new ArgsException(ArgsException.exceptions.SECONDOUTBAND); } if (secondArgs + thirdArgs > firstArgs.length()) { throw new ArgsException(ArgsException.exceptions.THIRDOUTBAND); } }}class ArgsException extends Exception { private String errMsg = new String(); public enum exceptions { NORMAL, FIRSTLESS, SECONDLESS, THIRDLESS, SECONDTYPEERROR, THIRDTYPEERROR, SECONDOUTBAND, THIRDOUTBAND } ; public ArgsException() { // TODO 自動生成構造函數存根 errMsg = "ARGS Error!!!"; } public ArgsException(exceptions e) { errMsg = "Please Input fellow the command format:\n" + "% java Probem3 hello 1 3\n"; switch (e) { case NORMAL: errMsg = "Please Input fellow the command format:\n" + "% java Probem3 hello 1 3\n"; case FIRSTLESS: errMsg += "Please input the frist parameter\n"; break; case SECONDLESS: errMsg += "Please input the second parameter\n"; break; case THIRDLESS: errMsg += "Please input the third parameter\n"; break; case SECONDTYPEERROR: errMsg += "The second parameter must be a integer, like 1,2,3,...,9,10,11,...\n"; break; case THIRDTYPEERROR: errMsg += "The third parameter must be a integer, like 1,2,3,...,9,10,11,...\n"; break; case SECONDOUTBAND: errMsg += "The second parameter out of the String's length\n"; break; case THIRDOUTBAND: errMsg += "The third parameter is too big, try a small one\n"; break; default: break; } } @Override public String toString() { return errMsg; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -