Created
November 19, 2013 13:45
-
-
Save jtulach/7545568 to your computer and use it in GitHub Desktop.
Is it a prime?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input | |
data-bind="value: number, valueUpdate: 'afterkeydown'" | |
placeholder="Type a number..."> | |
</input> | |
<p> | |
Is <span data-bind="text: number"></span> a prime? | |
<span data-bind="text: prime"></span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dew.demo.prime; | |
import net.java.html.json.Model; | |
import net.java.html.json.ComputedProperty; | |
import net.java.html.json.Property; | |
@Model(className="PrimeUI", properties={ | |
@Property(name="number", type=int.class), | |
}) | |
class PrimeDemo { | |
@ComputedProperty static boolean prime(int number) { | |
if (number <= 1) return false; | |
int squareRoot = (int)Math.sqrt(number); | |
for (int i = 2; i <= squareRoot; i++) { | |
if (number % i == 0) return false; | |
} | |
return true; | |
} | |
static { | |
new PrimeUI(2).applyBindings(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment