-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPracticeCodes.java
More file actions
32 lines (28 loc) · 818 Bytes
/
PracticeCodes.java
File metadata and controls
32 lines (28 loc) · 818 Bytes
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
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
class PracticeCodes {
public static int arr[] = {1,2,3,4,5};
public static int sumOfElement(int n){
if(n==0){
return arr[n];
}
return arr[n] + sumOfElement(n-1);
}
public static int factorial(int n){
if(n==0){
return 1;
}
return n * factorial(n-1);
}
public static int fibo(int n){
if(n==0 || n==1){
return n;
}
return fibo(n-1)+fibo(n-2);
}
public static void main(String[] args) {
System.out.println("Sum of all elements = "+sumOfElement(arr.length-1));
System.out.println("Factorial = "+factorial(5));
System.out.println("Fibo element = "+fibo(3));
}
}