Skip to content

Instantly share code, notes, and snippets.

@jtulach
Created November 19, 2013 13:45
Show Gist options
  • Save jtulach/7545568 to your computer and use it in GitHub Desktop.
Save jtulach/7545568 to your computer and use it in GitHub Desktop.
Is it a prime?
<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>
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