-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Fibonacci Series Code
- Loading branch information
Showing
6 changed files
with
83 additions
and
86 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
Program's_Contributed_By_Contributors/Java_Programs/DP/Fibonacci.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* | ||
* It is a sequence such that each number is the sum of the two preceding ones; and the sequence will start from the number 0 and 1. | ||
* Resources | ||
* https://en.wikipedia.org/wiki/Fibonacci_number | ||
* | ||
*/ | ||
|
||
|
||
|
||
import java.util.*; | ||
class Fibonacci | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
Scanner sc = new Scanner(System.in); | ||
int n = sc.nextInt(); | ||
fibo(n); | ||
} | ||
|
||
static void fibo(int n){ | ||
int a = 0, b = 1, i; | ||
if(n<1){ return; } | ||
|
||
System.out.print(a + " "); | ||
for(i = 1; i<n ; i++){ | ||
System.out.print(b + " "); | ||
int c = a+b; | ||
a = b; | ||
b = c; | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
100 changes: 50 additions & 50 deletions
100
...tors/Java_Programs/arrayIntersection.java → ...Java_Programs/Misc/ArrayIntersection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
public class arrayIntersection{ | ||
|
||
public static void intersect(int[] a,int[] b){ | ||
|
||
int minSize = (a.length>=b.length) ? b.length:a.length; | ||
int c[] = new int[minSize]; | ||
int z=0; | ||
for(int i=0;i<a.length;i++){ | ||
|
||
for(int j=0;j<b.length;j++){ | ||
|
||
if(a[i]==b[j]){ | ||
|
||
if(search(c, a[i])==-1){ | ||
c[z]=a[i]; | ||
z++; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
public static int search(int arr[],int a){ | ||
|
||
int start=0,end=arr.length-1; | ||
|
||
while(start<=end){ | ||
|
||
int mid=(start+end)/2; | ||
if(arr[mid]>a){ | ||
end=mid-1; | ||
}else if(arr[mid]<a){ | ||
start = mid+1; | ||
}else{ | ||
return mid; | ||
} | ||
|
||
} | ||
|
||
return -1; | ||
} | ||
|
||
public static void main(String[] args) { | ||
|
||
int arr1[] = { 1,2,3,4,5,6,7,8,9,10}; | ||
int arr2[] = { 5,6,7,8,9,10,11,12,13,14,15,16}; | ||
intersect(arr1,arr2); | ||
} | ||
public class ArrayIntersection{ | ||
|
||
public static void intersect(int[] a,int[] b){ | ||
|
||
int minSize = (a.length>=b.length) ? b.length:a.length; | ||
int c[] = new int[minSize]; | ||
int z=0; | ||
for(int i=0;i<a.length;i++){ | ||
|
||
for(int j=0;j<b.length;j++){ | ||
|
||
if(a[i]==b[j]){ | ||
|
||
if(search(c, a[i])==-1){ | ||
c[z]=a[i]; | ||
z++; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
public static int search(int arr[],int a){ | ||
|
||
int start=0,end=arr.length-1; | ||
|
||
while(start<=end){ | ||
|
||
int mid=(start+end)/2; | ||
if(arr[mid]>a){ | ||
end=mid-1; | ||
}else if(arr[mid]<a){ | ||
start = mid+1; | ||
}else{ | ||
return mid; | ||
} | ||
|
||
} | ||
|
||
return -1; | ||
} | ||
|
||
public static void main(String[] args) { | ||
|
||
int arr1[] = { 1,2,3,4,5,6,7,8,9,10}; | ||
int arr2[] = { 5,6,7,8,9,10,11,12,13,14,15,16}; | ||
intersect(arr1,arr2); | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
Program's_Contributed_By_Contributors/Java_Programs/Misc/Finobbaci.java
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
Program's_Contributed_By_Contributors/Java_Programs/hello.java
This file was deleted.
Oops, something went wrong.