Whats Wrong With This Solution That giving Me Wrong Answer (HIT)

This Question from October LunchTime 2019 Problem Code :HIT
My Solution:

Hi, @kushoz

Your solution halts with a failure on any valid input. It looks like you thought this through and you have the skeleton of a good solution. But if you test it locally on any test case, you will see that it stops immediately without printing anything.

Here are some things to look out for…

Lines 15-16:

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    Scanner sc = new Scanner(System.in);

Both br and sc can be used to read input. Advice: Pick one and use it throughout. The fact that you are using both is causing your main issue.

Lines 35-49…

        if(x==1){

(content elided)

        else {

(content elided)

        }

When x==1 (that is, when number of students is 4), your if statement does the same thing on both the if and the else branches. This is not wrong, but redundant and makes it harder to follow your reasoning. You should be able to verify that lines 44-48 work correctly for any valid student count.

Lines 51-52:

} catch(Exception e) {
	           }

Break the habit of having empty catch blocks on try/catch structures. ALWAYS include a statement to print the stack trace or rethrow the error further up the chain. If you had added the following statement inside the block, you would see where your program is failing during testing:

e.printStackTrace(System.out);

Explanation: printStackTrace() outputs the exception error message, and also shows you where in your code it originates from.

Good luck!

Thanks Bro It Workedk:grinning::slightly_smiling_face: