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

📄 ex1.java

📁 讲述各种各样的java初始编程 了解编程
💻 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 + -