You are not logged in. Please login at www.codechef.com to post your questions!

×

Run Time Error(NZEC) in java..plz help

import java.io.*;


public class SumInTriangle {
    public static void main(String args[]) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int[][] arr=new int[100][100];

    int testcases =Integer.parseInt(br.readLine());

    while(testcases>0)
    {

    int n = Integer.parseInt(br.readLine());
    for(int i=0;i<n;i++)
    {
    for(int j=0;j<=i;j++)
    arr[i][j]= Integer.parseInt(br.readLine());
    }
    for(int i=n-2;i>=0;i--)
    {
    for(int j=0;j<=i;j++)
    {
    arr[i][j]+=arr[i+1][j]>arr[i+1][j+1]?arr[i+1][j]:arr[i+1][j+1];
    }
    }
    System.out.printf("%d\n",arr[0][0]);
    testcases--;
    }


    }

}

I am getting a Run Time Error(NZEC) in this program..although it is working in my eclipse and giving correct output..plz help.. If any extra code line is needed or any new concept..plz explain it..because I am new to java and learning it..plz help..

asked 28 Jun '13, 22:44

shivam217's gravatar image

4★shivam217
8383515
accept rate: 20%

edited 28 Jun '13, 23:38

kunal361's gravatar image

4★kunal361
6.0k133272

can u pls provide the problem link!!!

(28 Jun '13, 23:40) kunal3614★
(28 Jun '13, 23:50) jaythegenius3★
(29 Jun '13, 00:32) shivam2174★

I havent checked your logic!!..Here is ur same code with different input technique!! http://ideone.com/3zI4Cl

(29 Jun '13, 00:35) jaythegenius3★

@jaythegenius thanks for the link..It really helped me..thank u very much...

(29 Jun '13, 00:41) shivam2174★

Yeah No problem!!

(29 Jun '13, 01:04) jaythegenius3★
showing 5 of 6 show all

Take this as a hint..
The problem you are getting is while taking input!!While running on ideone,it gives number format exception!!
Here is a link link text
Number format exception occurs when u try to convert a string into Number and when string is not appropriate. The string should not contain any blank spaces..Hope this helps.. Try some other method as an input!!

link

answered 28 Jun '13, 23:50

jaythegenius's gravatar image

3★jaythegenius
4253717
accept rate: 4%

edited 28 Jun '13, 23:52

I think @shivam217 is trying to solve SUMTRIAN.

@shivam217 It's giving NZEC error because of this line: arr[i][j]= Integer.parseInt(br.readLine()); In the input you'll have to read multiple numbers in a single line. That code only works when the line you're currently reading only has one number and nothing else.

link

answered 29 Jun '13, 00:02

junior94's gravatar image

4★junior94
3.2k143058
accept rate: 15%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,313
×434

question asked: 28 Jun '13, 22:44

question was seen: 1,706 times

last updated: 29 Jun '13, 01:04