package com.java1995;public class AgeText {? public static void main(String[] args) {?? try {???ageLeve(12);??} catch (IllegaAgeException e) {???// TODO Auto-generated catch block???e.printStackTrace();??}?}?? static String ageLeve(int age) throws IllegaAgeException{?? if(age>=10&&age<=22){??? return "少年 ";?? }else if(age<10){??? return "兒童";?? }else if(age>22&&age<120){??? return "成年";?? }else{??? //拋出異常??? throw new IllegaAgeException("非法的年齡?。?!");?? }? }}class IllegaAgeException extends Exception{?public IllegaAgeException(String msg){??super(msg);?}}我在main函數(shù)里輸入的年齡是12,為什么虛擬機輸出為空,不是應(yīng)該是青年的嗎?
添加回答
舉報
0/150
提交
取消