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

📄 throwsdemo.java

📁 Java语言程序设计-源代码(第三部分)和课程相对应的提供了一些用于学习理解的代码设计
💻 JAVA
字号:
import java.io.*;	
public class ThrowsDemo{	
static double c;	
public static  void main(String []args){
BufferedReader readin=new BufferedReader(new InputStreamReader(System.in));
	   try{
	           System.out.println("请任意输入一个被除数(数字): ");	
	           String  input1=readin.readLine();       //会产生 IOException
	           float a=Float.parseFloat(input1);        //会产生 NumberFormatException
	           System.out.println("请任意输入一个非零的除数: ");
String  input2=readin.readLine();       //会产生 IOException	
	           float b=Float.parseFloat(input2);       //会产生 NumberFormatException
	           c=division(a,b);	
	   }catch(IOException ioe){
	           System.out.println("系统输出入有问题 ");
	           System.out.println(ioe.getMessage());
	           System.out.println("程序无法处理即将中断 ");
	           System.exit(0);
	   }catch(NumberFormatException nfe){
System.out.println("所输入的数值是 :");
	           System.out.println(nfe.getMessage());
	           System.out.println("程序无法处理即将中断 ");		
	           System.exit(0);
	   }catch(ArithmeticException ae){
	            System.out.println(ae.getMessage());
	            System.exit(0);
	   }finally{
	            System.out.println("两数相除的结果是 :"+'\n'+c);
	             System.exit(0);
	   }
}
static double division(double x, double y)throws ArithmeticException{
if(y==0) throw new ArithmeticException("除数不能为0,否则结果是无限大 ");
	           double result;
	   result=x/y;
	   return result;
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -