finished implementing Factorial, began implementing IsInteger
This commit is contained in:
parent
5f46eb358e
commit
9d96d908f6
@ -12,9 +12,34 @@ What number would you like to compute the factorial for? 4
|
|||||||
24
|
24
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// TODO: Make tests for this class
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Factorial {
|
public class Factorial {
|
||||||
|
public static int factorial(int n)
|
||||||
|
{
|
||||||
|
// Base case
|
||||||
|
if (n < 1) return n;
|
||||||
|
|
||||||
|
// Recursive
|
||||||
|
return n * factorial(n - 1);
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
Scanner scan = new Scanner(System.in);
|
||||||
|
int input;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
System.out.print("What number would you like to computer the factorial for? ");
|
||||||
|
input = scan.nextInt();
|
||||||
|
|
||||||
|
result = factorial(input);
|
||||||
|
|
||||||
|
// Print the result
|
||||||
|
System.out.println(result);
|
||||||
|
|
||||||
|
// Close the scanner
|
||||||
|
scan.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,12 @@ public class IsInteger {
|
|||||||
// It is an integer if all of the characters in the string are digits.
|
// It is an integer if all of the characters in the string are digits.
|
||||||
//
|
//
|
||||||
// Return true if it is an integer, or false if it is not.
|
// Return true if it is an integer, or false if it is not.
|
||||||
//
|
public static isInteger(String input)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Check if you can convert
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user