标签:程序 身份证 类型 tin void nts finally int test
import java.util.*;
public class ExceptionTest {
public static void main(String[] args){
int a,b,c;
Scanner re=new Scanner(System.in);
System.out.println("请输入除数");
a=re.nextInt();
System.out.println("请输入被除数");
b=re.nextInt();
try{
c=a/b;
System.out.println(c);
}
catch(Exception t){
t.printStackTrace();
System.out.println("被除数为零");
}
finally{
System.out.print("程序继续");
}
}
}
运行结果:
import java.util.;
public class 圆 {
public static void main(String[] args){
double r,s;
final double PI=3.14;
Scanner re=new Scanner(System.in);
try{
System.out.println("请输入半径");
r=re.nextDouble();
s=rPI;
System.out.println(s);
}
catch(Exception t){
t.printStackTrace();
System.out.println("数据类型不匹配");
}
}
}
运行结果:
package 异常;
import java.util.*;
public class ID {
static void xy(int size)throws IllegalArgumentException {
if(size!=18) {
throw new IllegalArgumentException("长度不是18!");
}
}
public static void main(String[] args){
Scanner re=new Scanner(System.in);
System.out.println("请输入身份证号:");
String id=re.next();
try{
xy(id.length());
System.out.println(id);
}
catch(Exception t){
t.printStackTrace();
}
finally {
System.out.println("结束");
}
}
}
运行结果:
标签:程序 身份证 类型 tin void nts finally int test
原文地址:https://www.cnblogs.com/xiayan123147/p/10830952.html