I have written a Java application that I would like to run inside of a web page. How do I do this?
Code is below:
class Permutations {
static long factorial(int num){
long factorial = 1;
for (int forBlockvar = num; forBlockvar > 1; forBlockvar--) {
factorial = factorial * forBlockvar;
}
return factorial;
}
public static void main(String[] args){
long FactNmR;
int n = 10;
int num = n;
int r = 4;
int nMr = n - r;
long FactN = factorial(num);
if (nMr <= 1){
FactNmR = 1;
}
else {
num = nMr;
FactNmR = factorial(num);
}
long permutations = FactN;
permutations = permutations / FactNmR;
System.out.println(permutations);
}
}
There are several way to do this with java.
One way is to do it with Java Servlet.
You need a html form with an action that points to a Servlet (an extended Java Class) Have a look at this tutorial
Instead of running a server or applet, it is also possible to compile Java into JavaScript using JSweet.
This is JSweet's translation of your Permutations
class:
/* Generated from Java with JSweet 2.0.0 - http://www.jsweet.org */
var Permutations = (function () {
function Permutations() {
}
Permutations.factorial = function (num) {
var factorial = 1;
for (var forBlockvar = num; forBlockvar > 1; forBlockvar--) {
factorial = factorial * forBlockvar;
}
;
return factorial;
};
Permutations.main = function (args) {
var FactNmR;
var n = 10;
var num = n;
var r = 4;
var nMr = n - r;
var FactN = Permutations.factorial(num);
if (nMr <= 1) {
FactNmR = 1;
}
else {
num = nMr;
FactNmR = Permutations.factorial(num);
}
var permutations = FactN;
permutations = Math.floor(permutations / FactNmR);
console.info(permutations);
};
return Permutations;
}());
Permutations["__class"] = "Permutations";
Permutations.main(null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With