+ 1
An interesting code
What's your idea about my code? It calculates the factorial of your integer input. Appreciate your opinions! :) import java.util.Scanner; public class Calculation{ int factorial(int input){ int product= 1; int x= input; for(int z=0; z<input;z++){ product*=x; x--; } return product; } public static void main(String[] args){ Scanner input= new Scanner(System.in); Calculation o1= new Calculation(); System.out.println(o1.factorial(input.nextInt())); } }
3 Antworten
+ 3
Nice job. 👌
PS:
If you don't want to have to create an object to do the calculation you can make the factorial method static and call it directly.
+ 2
You can exclude X:
int factorial(int input) {
int product = 1;
for(int z = 1; z <= input; z++){
product *= z;
}
return product;
}
0
Thank you guys 👍🏻