}
public class FenShu {
private int fz;
private int fm;
public FenShu() {}
public FenShu(int fz, int fm) {
this.fz = fz;
this.fm = fm;
yueFen(fz,fm);
}
public void yueFen(int f1, int f2){
int x = f1;
int y = f2;
if(x < y){
int t;
t = x;
x = y;
y = t;
}
int n = x % y;
while(n!=0){
x = y;
y = n;
n = x % y;
}
this.fz /= y;
this.fm /= y;
}
public FenShu jia(FenShu fs) {
int zi=this.fz*fs.fm+fs.fz*this.fm;
int mu=this.fm*fs.fm;
return new FenShu(zi,mu);
}
public FenShu jian(FenShu fs) {
int zi=this.fz*fs.fm-fs.fz*this.fm;
int mu=this.fm*fs.fm;
return new FenShu(zi,mu);
}
public FenShu cheng(FenShu fs) {
int zi = this.fz * fs.fz;
int mu = this.fm * fs.fm;
return new FenShu(zi, mu);
}
public FenShu chu(FenShu fs) {
int zi =this.fz*fs.fm;
int mu =this.fm*fs.fz;
return new FenShu(zi,mu);
public static void main(String[] args) {
try{
int []arr=new int[3];
System.out.println(arr[5]);
}catch(Exception e){
e.printStackTrace();
}
finally{
try{
int a=3/0;
System.out.println(a);
}catch(Exception e){
e.printStackTrace();
}
}
}
输出结果:
java.lang.ArrayIndexOutOfBoundsException: 5
at basic.program.test.SDFSFS.main(SDFSFS.java:11)
java.lang.ArithmeticException: / by zero
at basic.program.test.SDFSFS.main(SDFSFS.java:17)