-->

Close to century

Posted by Admin on
Given the score of a batsman and an integer n, return true if the score is within n of a multiple of 100. For e.g. if the score is 186 and n = 15, the output is true. If score is 392 and n=5, the output is false. If score is 409 and n = 12 the output is true


public class CloseToCentury {

       static int testcase11 = 392;
       static int testcase12 = 5;
      
       public static void main(String args[]){
              CloseToCentury testInstance = new CloseToCentury();
              boolean result = testInstance.century(testcase11,testcase12);
              System.out.println(result);
       }
      
       //write your code here
       public boolean century(int score, int nearness){
       score=score%100;
       if(score>50)
       {
              score=100-score;
              if(score<=nearness)
              {
                     return true;
              }
              else
              {
                     return false;
              }
       }
       else
       {
              if(score<=nearness)
              {
                     return true;
              }
              else
              {
                     return false;
              }
       }
       }     
}


Please comment if you find any mistake.

No comments:

Post a Comment