Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organize Java Directory and fix code #336

Merged
merged 1 commit into from
Oct 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.