Skip to content

Commit

Permalink
Merge pull request #336 from tuminzee/contribution
Browse files Browse the repository at this point in the history
Organize Java Directory and fix code
  • Loading branch information
fineanmol committed Oct 2, 2021
2 parents 0588012 + 5bee55f commit 675b7bd
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 86 deletions.
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;
}
}
}
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);
}
}

This file was deleted.

This file was deleted.

0 comments on commit 675b7bd

Please sign in to comment.