Why it is always giving number format exception?

Please help me with this…
I know this program works good in ide installed in our local PC but when I copy paste the same code in the codechef ide it is giving me number format exception.
Do I need to perform null checks? but why?
public class Codechef {
public static void main(String[] args) throws Exception {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

        int len = Integer.parseInt(bf.readLine());

        String str[] = bf.readLine().split("\\s");
        int ar[] = Arrays.stream(str).mapToInt(Integer::parseInt).toArray();
        Arrays.sort(ar);
        int ans = ar[len - 2];


        System.out.println(ans);

    }
}

Since I am good with java I coded it in the same, but it is not working? Should I switch to c++?

Please post the stacktrace. (i.e. the full error you get)
Also please tell me what question you tried to run this for.

If I rename class to Main, and set ‘custom input’ to:
5
1 2 3 4 5
it works correctly and return penultimate number:
4

problem is what you write to input

But if we set it custom input ,it will work but what if the testcases will be passed by the codechef end?

This is the question:
Chef and Dhyey have become friends recently. Chef wants to test Dhyey’s intelligence by giving him a puzzle to solve.

The puzzle contains an integer sequence A1,A2,…,AN. The answer to the puzzle is the maximum of Ai%Aj, taken over all valid i, j.

Help Dhyey solve this puzzle.

Input
The first line of each test case contains a single integer N.
The second line contains N space-separated integers A1,A2,…,AN.
Output
For each test case, print a single line containing one integer — the answer to the puzzle.

Constraints
2≤N≤105
1≤Ai≤109 for each valid i
Subtasks
Subtask #1 (30 points): 2≤N≤1,000
Subtask #2 (70 points): 2≤N≤105
Example Input 1
5
1 2 3 4 5
Example Output 1
4
Example Input 2
6
5 5 5 2 3 8
Example Output 2
5

Actually it is not taking the input given from the codechef end,that is the reason it is throwing number format exception

Sure, this is not real java enviroment, this is html/javascript web client for sending your code (text file) to server where is no human to types keyboard to input.

So you can test if input is empty, or catch number format exception and inform user about correct input format

Hi,
Thanks for reverting back,
Could you please write a sample program using BufferReader and InputStreamReader here,that really helps me a lot

I usually code in java

You can look at my submissions

also can you give link to this prob so that we can try it
Edit:- got it, its prob from this long.
btw i usually split the string with " " since they are space separated

String line1 = bf.readLine();
if (line1 == null) {
   System.out.println("Empty input");
   return;
}
int len = Integer.parseInt(line1);

Hi,
Even if we write split("\s") it will do the same there is nothing wrong with that,
So what I realized is it is just showing you the error while compiling the code but if you submit the code, it will remove those Re error& exceptions.
And scanner will always throws the error at compilation time but it will consider the class on submitting it

Did you even try what i said

i read online that \s matches 1 space char

then what if space between digits is more than 1 char

I solved it in java so i know that my way works for sure