public class YiChang {
public static void main(String[] args){
for(int i=0;i<4;i++){
int k;
switch(i){
case 0: int zero=0;
try{
k=911/zero;
}catch(ArithmeticException e){
System.out.println("出现算数异常!");
}
break;
case 1:
try{
int b[]=null;
k = b[0];
}catch(NullPointerException e){
System.out.println("出现空指针异常!");
}
break;
case 2:
int c[]=new int[2];
try{
k=c[9];
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("出现数组序号溢出!");
}
break;
case 3:
try{
char ch="abc".charAt(99);
}catch(StringIndexOutOfBoundsException e){
System.out.println("出现数据类型转换异常!");
}
break;
}
}
}
}
public class InsufficientFundsException extends Exception {
public String getMessage(){
return "您的余额不足!";
}
}
public class NagativeFundsException extends Exception{
public String getMessage(){
return "取款金额不能为负数!";
}
}
public class Bank {
private static double balance;
Bank(){
};
Bank(double balance){
this.balance=balance;
}
public static void withDrawal(double dAmount) throws InsufficientFundsException,NagativeFundsException{
if(dAmount>balance){
throw new InsufficientFundsException();
}
if(dAmount<0){
throw new NagativeFundsException();
}
}
public static void main(String[] args){
Bank b=new Bank(100);
System.out.println("我有"+balance+"元存款!");
try{
withDrawal(150);
}catch(InsufficientFundsException | NagativeFundsException e){
e.printStackTrace();
}
try{
withDrawal(-15);
}catch(NagativeFundsException |InsufficientFundsException e){
e.printStackTrace();
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有