I am an eighth grader with a school project of creating and application in Java that returns the total permutations of two given numbers. It needs to be light and efficient, for later deployment on a website. I was wondering if there was any way I could improve the code so it would be more efficient.
class Factorials {
public static void main(String[] args){
int n = 8;
long factorialN = n;
for (int ForN = n; ForN <= n && ForN > 1; ForN--) {
factorialN = factorialN * ForN;
}
factorialN = factorialN / n;
System.out.println(factorialN);
int r = 6;
int rMinus1 = r - 1;
long factorialR = rMinus1;
for (int ForR = rMinus1; ForR <= rMinus1 && ForR > 1; ForR--) {
factorialR = factorialR * ForR;
}
factorialR = factorialR / rMinus1;
System.out.println(factorialR);
int nMr = n - r;
System.out.println(nMr);
long factorialNmR = nMr;
if (nMr == 2) {
factorialNmR = 2;
}
else if (nMr <= 1){
factorialNmR = 1;
}
else if (nMr > 2) {
for (int FornMr = nMr; FornMr <= nMr && FornMr > 1; FornMr--) {
factorialNmR = factorialNmR * FornMr;
}
factorialNmR = factorialNmR / nMr;
System.out.println(factorialNmR);
}
long permutations = factorialN;
System.out.println(permutations);
permutations = permutations / factorialNmR;
System.out.println(permutations);
}
}