got practice question wrong by faulty compilation?

I entered the below code in the editor for submitting my answer and I got a compile error saying that my file name was not matching my class!?! I never specified a class name.

I tried sending a file attachment and same failure error. Here is my code:

//Bear and Candies 123 = Beginner problem on CodeChef

import java.util.Scanner;

public class Bears {

public static void main(String[] args) {

  int testCaseNumber = 0;
  String testCase = "";

  Scanner inputReader = new Scanner(;
  // Get the number of test cases from the user
  while (testCaseNumber < 1 || testCaseNumber > 1000) {
     System.out.println("Enter the number of test cases 1 <= number <= 1000:");
     testCaseNumber = inputReader.nextInt();
  for(int i = 1; i <= testCaseNumber; i++) {
     	int a = 0;   
      int b = 0;
        int limak = 0;
        int bob = 0;
     while((a < 1 || b < 1) || (a > 1000 || b > 1000)) {
        System.out.println("For test case #" + i + " Give two integers for the candy limit of Limak and Bob respectively 1 <= A&B <= 1000:");
        testCase = inputReader.nextLine();
        String[] numbers = testCase.split(" "); 
      a = Integer.parseInt(numbers[0]);    
      b = Integer.parseInt(numbers[1]);
     for(int j = 1; j <= 1000; j += 2){
        // check limak
        limak += j;
        if(limak > a){
        //check bob
        bob += j + 1;
        if(bob > b){


Hey @foo_eagle, you have a public class named Bears. On the Codechef platform, to submit a Java solution you get two options for naming your class.

  1. If your class is public, it must be named Main.
  2. If your class is not public, you can name it whatever you like.
    Here is your solution which compiles and executes, but gives a WA (wrong answer) verdict.

I see that you are prompting the user for input with print statements such as System.out.println("Enter the number of test cases 1 <= number <= 1000:");. This is not required on Codechef and other competitive programming platforms, and always leads to a wrong answer verdict since the testing is automated. If you add unnecessary data to the output the judge is unable to match your output to the correct output. You must strictly follow the input/output format described in the problem statement. Refer to here for details. Also, you do not need to test whether the input follows the constraints, it is guaranteed to do so. Refer to FAQ for other basic information you might need.

Welcome, and good luck :slight_smile: