Skip to content

Instantly share code, notes, and snippets.

@sunmeat
Last active December 19, 2021 10:20
Show Gist options
  • Save sunmeat/505adaf35649894bc304 to your computer and use it in GitHub Desktop.
Save sunmeat/505adaf35649894bc304 to your computer and use it in GitHub Desktop.
static methods
package com.alex.static;
class Algorithm {
public static double pi = 3.14159;
public static int Factorial(int x) {
if (x == 1) {
return 1;
} else {
return x * Factorial(x - 1);
}
}
public static int Fibonachi(int x) {
if (x == 0 || x == 1) {
return 1;
} else {
return Fibonachi(x - 1) + Fibonachi(x - 2);
}
}
}
public class Program {
public static void main(String[] args) throws Exception {
System.out.println(Algorithm.Factorial(5));
System.out.println(Algorithm.Fibonachi(5));
System.out.println(Math.sqrt(5));
System.out.println(Math.pow(5, 5));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment