我编写了一个我希望在网页中运行的Java应用程序。我该怎么做?
代码如下:
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);
}
}
答案 0 :(得分:7)
答案 1 :(得分:2)
也可以使用JSweet将Java编译为JavaScript,而不是运行服务器或applet。
这是JSweet对您的Permutations
课程的翻译:
/* 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);