daily pastebin goal
85%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Main {
  2.     public static void main(String[] args){
  3.         Scanner scan = new Scanner(System.in);
  4.         System.out.println("Please enter the name of the method you want to run.");
  5.         String method = scan.next();
  6.         if (method.equals("recursivePrinter")){
  7.             System.out.println("Please enter the input for the method.");
  8.             int num = scan.nextInt();
  9.             recursivePrinter(num);
  10.         }
  11.         if (method.equals("reversePrint")){
  12.             System.out.println("Please enter the input for the method.");
  13.             String word = scan.next();
  14.             reversePrint(word);
  15.             System.out.println();
  16.         }
  17.         if (method.equals("factorial")){
  18.             System.out.println("Please enter the input for the method.");
  19.             int num  = scan.nextInt();
  20.             System.out.println(factorial(num));
  21.         }
  22.     }
  23.     public static void recursivePrinter(int levels){
  24.         if (levels > 0){
  25.             System.out.println("Going down! " + levels);
  26.             recursivePrinter(levels-1);
  27.         }
  28.         if (levels != 0) {
  29.             System.out.println("Coming back up! " + levels);
  30.         }
  31.     }
  32.     public static void reversePrint(String str){
  33.         if (str.length() >= 1) {
  34.             System.out.print(str.substring(str.length()-1,str.length()));
  35.             reversePrint(str.substring(0,str.length()-1));
  36.         }
  37.     }
  38.     public static int factorial(int num){
  39.         int result;
  40.         if(num<=1) {
  41.             return 1;
  42.         }
  43.         else {
  44.             result = factorial(num - 1) * num;
  45.             return result;
  46.         }
  47.     }
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top