-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecur.java
More file actions
54 lines (45 loc) · 1.01 KB
/
Recur.java
File metadata and controls
54 lines (45 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.Scanner;
public class Recur {
// public static int fib(int n){
// if (n == 1)
// return 1;
// if (n == 2)
// return 1;
// else
// return fib(n-1) + fib(n-2);
// }
// public static void f (int n) {
// System.out.println(n);
// if (n > 1)
// f(n-1);
// }
// public static void g(int n) {
// if (n > 1)
// g(n-1);
//
// System.out.println(n);
// }
public static void h(int n) {
System.out.println(n);
if (n > 1)
h(n-1);
System.out.println(n);
}
public static void main (String args[]) {
Scanner scan = new Scanner (System.in);
System.out.print("What is N? ");
int n = Integer.valueOf(scan.nextLine());
//// System.out.println("Result is " + fib(n));
//
// System.out.println("Output from function f");
// f(5);
////
// System.out.println("Output from function g");
// g(n);
//
System.out.println("Output from function h");
h(n);
// System.out.println("Output from function h");
// h(n);
}
}