public class id {
String a;
public void setId(String id){
if (id.length() == 18) {
this.a = a;
} else {
throw new IllegalArgumentException("身份证号码长度应为18!");
}
}
public static void main(String[] args) {
id ac = new id ();
try {
ac.setId("0123456789123456789");
} catch (IllegalArgumentException ie) {
System.out.println(ie.getMessage());
}
}
}
import java.util.;
public class yuan {
public static void main(String[] args){
double a,p=3.14f,s=0;
Scanner sc = new Scanner(System.in);
try{
a=sc.nextDouble();
s=aa*p;
}
catch(InputMismatchException e){
System.out.print("输入错误!");
}
System.out.print(s);
}
}
import java.util.*;
public class take {
public static void main(String[] args){
int a,b,c=0;
Scanner ac= new Scanner(System.in);
System.out.print("请输入被除数:");
a=ac.nextInt();
System.out.print("请输入除数:");
b=ac.nextInt();
try{
c=a/b;
}
catch(ArithmeticException e){
System.out.print("除数不能为0!");
}
System.out.print("\n");
System.out.print(c);
}
}
原文:https://www.cnblogs.com/1786722420yang/p/10830980.html