Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
jb14.0 tests
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.util.function.IntPredicate; import java.lang.*; import java.math.*; class Rextester { public static void main(String args[]) { System.out.println("Hello, World!"); MyTest t = n -> n >= 10? (n<=20? true: false) : false; System.out.println(t.testing(5)); System.out.println(t.testing(10)); System.out.println(t.testing(15)); System.out.println(t.testing(20)); System.out.println(t.testing(25)); System.out.println("---"); NumericFunc factorial = n -> { int result = 1; for(int i = n; i>1; i--) result *= i; return result; }; System.out.println(factorial.func(1)); System.out.println(factorial.func(2)); System.out.println(factorial.func(3)); System.out.println(factorial.func(4)); System.out.println(factorial.func(5)); System.out.println("---"); NumericFuncT<Double> factorialT = n -> { Double result = 1.0; for(int i = n.intValue(); i>1; i--) result *= i; return result; }; System.out.println(factorialT.func(6.0)); System.out.println("---"); MyIntFubric mif = MyIntNum::new; MyIntNum min = mif.create(10); IntPredicate ip = min::hasCommonFactor; System.out.println(ip.test(4)); System.out.println(ip.test(3)); System.out.println(ip.test(5)); System.out.println(ip.test(8)); System.out.println("---"); } } interface MyIntFubric{ MyIntNum create(int n); } class MyIntNum{ int _n; MyIntNum(int n){ _n = n; } public boolean hasCommonFactor(int m){ boolean result = false; for(int i=2; i<=(Math.min(_n, m))/2; i++){ if((_n%i == 0) && (m%i == 0)){ result = true; break; } } return result; } } interface MyTest{ boolean testing(int n); } interface NumericFunc{ int func(int n); } interface NumericFuncT<T>{ T func(T n); }
run
|
edit
|
history
|
help
0
Memory cleanup
// Java Coding Challenge - 06: Print out Fibonacci numbers 0 - 93
Use of JS in Java (not my)
hello!
forloop1
OBF-7 PR
Scope
Homework
Alumnos Java con Input
Fgh