Ad
Code
Diff
  • public class Kumite {
      public static boolean IsThree(int x) {
        // Modulo of negative number would be negative.
        // To avoid that, we convert any negative input into positive.
        if (x < 0) x *= -1;
        
        while(x > 0) {
          if(x % 10 == 3) 
            return true;
          x /= 10;
        }
        return false;
      }
    }
    • public class Kumite {
    • public static boolean IsThree(int x) {
    • // Modulo of negative number would be negative.
    • // To avoid that, we convert any negative input into positive.
    • if (x < 0) x *= -1;
    • while(x > 0) {
    • if(x % 10 == 3)
    • return true;
    • x /= 10;
    • }
    • return false;
    • }
    • }