finished implementing Factorial, began implementing IsInteger

This commit is contained in:
Jellyfish 2025-09-14 02:54:15 -07:00
parent 5f46eb358e
commit 9d96d908f6
2 changed files with 38 additions and 7 deletions

View File

@ -12,9 +12,34 @@ What number would you like to compute the factorial for? 4
24
*/
// TODO: Make tests for this class
import java.util.Scanner;
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) {
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();
}
}

View File

@ -2,12 +2,18 @@ package isInteger;
public class IsInteger {
// Given a string, determine if it is an integer. For example the
// string 123 is an integer, but the string hello is not.
//
// 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.
//
// Given a string, determine if it is an integer. For example the
// string 123 is an integer, but the string hello is not.
//
// 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.
public static isInteger(String input)
{
// Check if you can convert
}
}