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;
- }
- }
import junit.framework.*; public class JavaTest extends TestCase { public void tests() { assertFalse(Kumite.IsThree(525458)); assertFalse(Kumite.IsThree(2222)); assertTrue(Kumite.IsThree(354523)); assertTrue(Kumite.IsThree(748504231)); assertTrue(Kumite.IsThree(-3)); } }
- import junit.framework.*;
- public class JavaTest extends TestCase {
- public void tests() {
- assertFalse(Kumite.IsThree(525458));
- assertFalse(Kumite.IsThree(2222));
- assertTrue(Kumite.IsThree(354523));
- assertTrue(Kumite.IsThree(748504231));
- assertTrue(Kumite.IsThree(-3));
- }
- }