学习了一点java ,写程序时遇到一个问题,想让从命令行中读取的参数来指导下一步工作可以吗?
下面是我写的实现优先级队列的一个主函数,总是报错说“Exception in thread "main" the current array has been sortes,now you can execut four commend like:Maximum”
java.lang.ArrayIndexOutOfBoundsException: 0
at com.nana.Queues.main(Queues.java:72)
public static void main(String[] args){
System.out.println("the current array has been sortes,now you can execut four commend like:Maximum,");
int i=0;
Queues Qu=new Queues();
Qu.BUILDMAXHEAP(A);
do{
switch(args[i]){
case "Maximum":Qu.Maximum(A);break;
case"Extract-max":Qu.Extractmax(A);break;
case"increasekey":System.out.println("please input the number you want to increase and the target:");
Qu.Increasekey(A, Integer.parseInt(args[i+1]), Integer.parseInt(args[i+2]));break;
case "exit":i=-2;break;
case"insert":System.out.println("please input the number you want to insert:");
Qu.Insert(A,Integer.parseInt(args[i+1]) );break;
}
i++;
}while(i!=-1);
}