import java.io.*;class JavaThrows{
public int compute(int x) throws ArithmeticException{
int z=100/x;
return z;}
public void method1(){
int x;
while(true){
try{
x=System.in.read();
x=x-48;
x=compute(x);
System.out.println(x);}
catch(IOException ioe){
System.out.println("read error");}
catch(ArithmeticException e){
System.out.println("devided by 0");}
}
}
public static void main(String args[]){
JavaThrows t1=new JavaThrows();
t1.method1();}
}运行看看输出
怎么老是更着两个-2
-2
public int compute(int x) throws ArithmeticException{
int z=100/x;
return z;}
public void method1(){
int x;
while(true){
try{
x=System.in.read();
x=x-48;
x=compute(x);
System.out.println(x);}
catch(IOException ioe){
System.out.println("read error");}
catch(ArithmeticException e){
System.out.println("devided by 0");}
}
}
public static void main(String args[]){
JavaThrows t1=new JavaThrows();
t1.method1();}
}运行看看输出
怎么老是更着两个-2
-2
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货