请教runtime error

[复制链接]
查看11 | 回复1 | 2009-4-2 16:12:45 | 显示全部楼层 |阅读模式
请看以下代码,我看了很多遍,都不知错在哪里。提交后老是显示runtime error 。我修改了我觉得会错的地方,现在觉得越修改越难看,但是还是runtime error。是数组问题吗?还是其他问题?请高手指点。
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Scanner;
import java.util.ArrayList;
public class Test {

public static void main(String[] args){

//输入数据;

ArrayList array = new ArrayList(), array2 = new ArrayList(), array3 = new ArrayList();

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

int[][] way ;

int minCost = 100;

int minNum = 0;

int sure = 0;

int size = 0;

int sum = 0;

int temp = 0;

int mount = 0;

Scanner scan;

try{

mount = Integer.parseInt(in.readLine());

while(mount != 0){

way = new int[mount][mount];

for(int m = 0;m < mount; m++){

for(int n = 0; n < mount; n++){

way[m][n] = 100;

}

}

for(int i = 0; i < mount-1; i++){

scan = new Scanner(in.readLine());

scan.next();

int n = Integer.parseInt(scan.next());

for(int j = 1; j <= n; j++){

temp = scan.next().charAt(0) - 'A';

way[temp] = way[temp] = Integer.parseInt(scan.next());

while(scan.hasNext())

scan.next();

}

}

//开始计算最小生成树;

array.add(new Integer(sure));

size = array.size();

while(size != mount){

for(int m = 0; m< size ; m++){

sure = (Integer)array.get(m);

for(int k = 0 ; k < mount ; k++){

if(way[sure][k] < minCost){

if(!array.contains(k)){

minCost =way[sure][k];

minNum= k;

}

}

}

}

array.add(new Integer(minNum));

array2.add(new Integer(minCost));

minCost = 100;

minNum = 0;

size = array.size();

}

while(!array2.isEmpty()){

sum = sum + (Integer)array2.remove(0);

}

array.clear();

array3.add(new Integer(sum));

sure = 0;

sum = 0;

mount = Integer.parseInt(in.readLine());

}

while(! array3.isEmpty())

System.out.println((Integer)array3.remove(0));

}catch(IOException e ){}
}
}

回复

使用道具 举报

千问 | 2009-4-2 16:12:45 | 显示全部楼层
An error that occurs during the execution of a program. In contrast, compile-time errors occur while a program is being compiled. Runtime errors indicate bugs in the program or problems that the designers had anticipated but could do nothing about. For example, running out of memory will often cause a runtime error.(运行时错误是程序执行期间...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行