Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
jb14 isEven Links
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; import java.math.*; class Rextester { public static void main(String args[]) { System.out.println("Hello, World!"); MyIntNum t = new MyIntNum(10); TestLink tl = t::hasCommonFactor; System.out.println("10 & 6=true "+tl.test(6)); MyIntNum t2 = new MyIntNum(81); TestLink tl2 = t2::hasCommonFactor; System.out.println("81 & 5= false "+tl2.test(5)); System.out.println("81 & 6= true "+tl2.test(6)); System.out.println("81 & 27= true "+tl2.test(27)); } } interface TestLink{ boolean test(int n); } class MyIntNum{ private int _x; MyIntNum(int x){ _x = x; } public boolean hasCommonFactor(int y){ boolean result = false; boolean yIsEven = (y%2==0); boolean xIsEven = (_x%2==0); System.out.println(y + " yIsEven="+ yIsEven +" "+_x+" xIsEven=" + xIsEven); if(yIsEven == xIsEven){ for(int i = (yIsEven) ? 2 : 3; i<Math.min(y,_x); i+=2){ System.out.println(i); if( (y%i == 0) && (_x%i == 0) ){ result = true; break; } } } return result; } }
run
|
edit
|
history
|
help
0
// Java Coding Challenge - 10: Palindrome numbers
rta
Number to Words (Accenture)
nth fibonacci ( memoization )
UserDefinedBar
Firstproject
uraian angka
pow x^n
ex25
combination sum (variation)