关于java中队列抛出异常问题

来源:百度知道 编辑:UC知道 时间:2024/09/28 15:42:00
class queue{
private int front=0,rear=0,c=0; //队首位置,队尾位置,队列中元素个数
private int array[ ],len;//数组及数组长度

public static void main(String args[ ]){

queue aa=new queue(7);
aa.in(1);
aa.in(1);
aa.in(1);
aa.in(1);
aa.out();
aa.out();
aa.out();
aa.out();
aa.out();
class EmptyQueueException extends Exception{//自定义异常类
public EmptyQueueException (String msg){
super (msg);
}
public String getMessage (){//覆盖父类的方法
return "队列已空,执行出队操作引发异常" ;
}
}

public int out()throws EmptyQueueException{
if (!isEmpty()){
c--;
int result=array[front];
front= (front+1)%len;
return result;
}
else throw new EmptyQueueException("队列已空");
}
}
public queue (int s){
arra

说实话,你这程序有点乱,看不太明白。
建议你先看看Java程序结构和类方面的资料。

另外,异常部分也是一个重点和难点,建议你多看点资料和示例。

你什么意思??没看明白。