Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪位高手看一看 我的代码为什么runtime error啊

Posted by Kerence at 2011-05-20 17:49:23 on Problem 1163
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String strNum = bf.readLine();
		int n = Integer.parseInt(strNum);
		int triangle[][] = new int[100][100];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < i + 1; j++) {
				String strTriEle = bf.readLine();
				triangle[i][j] = Integer.parseInt(strTriEle);

			}
		}

		// 判断各次的值
		int temp = 0;
		for (int i = 1; i < n; i++) {
			for (int j = 0; j < i + 1; j++) {
				if (j >= 1) {
					triangle[i][j] = triangle[i][j] + Math.max(triangle[i-1][j-1],triangle[i-1][j]);
					temp = triangle[i][j];
				}else {
					temp = triangle[i][j] = triangle[i-1][j] + triangle[i][j];
				}
			}
		}
		int maxVal = 0;
		for (int i = 1; i < n; i++) {
			if( triangle[n-1][i] > maxVal){
				maxVal = triangle[n-1][i];
			}
		}
		System.out.println(maxVal);

	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator