哪位大侠帮忙看下我的JAVA程序哪错了!!!!!!!!!

来源:百度知道 编辑:UC知道 时间:2024/05/28 09:47:39
class oushu extends Exception{
oushu(){
System.out.println("结果不是偶数!");
}
}
class benshen extends Exception{
benshen(){
System.out.println("结果是除数本身!");
}
}

public class CustomException{
public static void main(String [] args){
int a[]={4,8,15,32,64,127,256,512};
int b[]={2,1,2,4,4,4,8};
int c[];
for(int i=0;i<7;i++){
c[i]=a[i]/b[i];
}
try{
check(c);
}catch(Exception e){
System.out.println(e);
}
}

void check(int n[]=new int[7]) throws oushu,benshen{
int b[]={2,1,2,4,4,4,8};
for(int i=0;i<7;i++){
if((n[i]%2)!=0){
throw new oushu();
}
if(n[i]==b[i]){
throw new benshen();
}
}
}
}

程序本身问题也真多,逻辑也很混,想必是个初手吧,我把你的程序改了下,你看下是否是你想实现的功能!
class oushu extends Exception{
oushu(){
System.out.println("结果不是偶数!");
}
}
class benshen extends Exception{
benshen(){
System.out.println("结果是除数本身!");
}
}

public class CustomException{
public static void main(String [] args){
int a[]={4,8,15,32,64,127,256,512};
int b[]={2,1,2,4,4,4,8};
int c[]={0,0,0,0,0,0,0};
for(int i=0;i<7;i++){
c[i]=a[i]/b[i];

try{
if((c[i]%2)!=0){
throw new oushu();
}
if(c[i]==b[i]){
throw new benshen();
}
}catch(Exception e){
System.out.println(e);
}
}
}
}