diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5f05927 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +out +*.iml \ No newline at end of file diff --git a/src/Digits.java b/src/Digits.java new file mode 100644 index 0000000..b515d37 --- /dev/null +++ b/src/Digits.java @@ -0,0 +1,41 @@ +/** + * This class output a digit in verbal form. + */ +public class Digits { + + // Array of digit's verbal form. + private static String[] digitArray = { + "zero", + "one", + "two", + "three", + "four", + "five", + "six", + "seven", + "eight", + "nine", + }; + + /** + * Method make digit in verbal form. + * @param digit - Digit for translate. + * @return Answer with digit in digital and verbal forms. + */ + public static void digitToString(int digit){ + try{ + System.out.println("Your digit " + digit + " is " + digitArray[digit]); + } + catch(IndexOutOfBoundsException e){ + System.out.println("Your input is not a simple digit. Try use (0,...,9)."); + } + } + + public static void main(String argv[]){ + // right use + digitToString(5); + + //wrong use + digitToString(4566); + } +} \ No newline at end of file diff --git a/src/Factorial.java b/src/Factorial.java new file mode 100644 index 0000000..61d87ea --- /dev/null +++ b/src/Factorial.java @@ -0,0 +1,40 @@ +/** + * This class calculates factorial of the number. + */ +public class Factorial { + + /** + * Not recursive method to calculates the factorial. + * @param num - The number for calculates factorial. + * @return factorialResult - Factorial for this number. + */ + public static int factorialUnRecursive(long num) { + int factorialResult=1; + + for (; num > 0; factorialResult *= num--); + + return factorialResult; + } + + /** + * Recursive method to calculates the factorial. + * @param num - The number for calculates factorial. + * @return Factorial for this number. + */ + public static int factorialRecursive(int num) { + return (num == 0) ? 1 : num * factorialRecursive(num - 1); + } + + + public static void main(String argv[]){ + long factorialTest = 10; + System.out.println("Factorial " + factorialTest + " is " + factorialUnRecursive(factorialTest)); + + int factorialTest2 = 10; + System.out.println("Factorial " + factorialTest + " is " + factorialRecursive(factorialTest2)); + } + + +} + + diff --git a/src/FibonacciRow.java b/src/FibonacciRow.java new file mode 100644 index 0000000..f484d08 --- /dev/null +++ b/src/FibonacciRow.java @@ -0,0 +1,29 @@ +/** + * This class calculates the number of the Fibonacci row. + */ +public class FibonacciRow { + + /** + * @param num - The number is less than that calculates Fibonacci row. + * @return fibonacciResult - String with Fibonacci row. + */ + public static String fibonacciRow(int num) { + String fibonacciResult = ""; + int fibonacciNumber = 0; + + for (int i = 1; i