Skip to content

Instantly share code, notes, and snippets.

@jtulach
Last active November 12, 2017 12:32
Show Gist options
  • Save jtulach/dd7ab83a1acec7a7faac076dece3b837 to your computer and use it in GitHub Desktop.
Save jtulach/dd7ab83a1acec7a7faac076dece3b837 to your computer and use it in GitHub Desktop.
Greatest Divisor of two numbers
package dew.demo.namesmodel;
import net.java.html.json.Model;
import net.java.html.json.Property;
import net.java.html.json.ComputedProperty;
@Model(targetId="", className="GreatDiv", properties={
@Property(name = "a", type=int.class),
@Property(name = "b", type=int.class)
})
class GreatestDivisor {
@ComputedProperty
static int nsd(int a, int b) {
if (a < b) {
return nsd(b - a, a);
} else if (a > b) {
return nsd(a - b, b);
}
return a;
}
public static void main(String... args) {
GreatDiv pageModel = new GreatDiv(9,15);
pageModel.applyBindings();
}
}
a: <input data-bind="textInput:a"/>
b: <input data-bind="textInput:b"/>
Greatest divisitor of a and b: <span data-bind="text: nsd"></span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment