Added Fakultaet.java as a Example for friday

This commit is contained in:
Jochen Seyfried 2024-07-04 10:09:59 +02:00
parent e801717444
commit 4dfea0d69d

20
src/Fakultaet.java Normal file
View File

@ -0,0 +1,20 @@
class Fakultaet {
public int fak(int number) {
if (number < 0) {
return 1;
}
int factorial = 1;
int i = 1;
while(i <= number){
factorial = factorial * i;
i = i + 1;
}
return factorial;
}
public static void main(String[] args) {
Fakultaet f = new Fakultaet();
int result = f.fak(5);
print(result);
}
}