Skip to content

Commit

Permalink
ArrayInv+Pattern+BinarySearch
Browse files Browse the repository at this point in the history
  • Loading branch information
riyakushwaha committed Oct 10, 2020
1 parent bc101d8 commit 06f2bbe
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
34 changes: 34 additions & 0 deletions ArrayInverse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import java.util.Scanner;

public class ArrayInverse {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

int n = scanner.nextInt();
int [] a = new int [n];

int num =0;
for(int i =0; i<n; i++)
{
a[i]= scanner.nextInt();
num+= i * (int) Math.pow(10, a[i]);

}

// System.out.println(num);

for(int i =0; i<n; i++)
{
a[i] =num%10;
num= num/10;
}

for( int i =0; i<n; i++)
{
System.out.print(a[i]+" ");
}


}

}
48 changes: 48 additions & 0 deletions BinarySearch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import java.util.Scanner;

public class BinarySearch {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int [] a = new int [n];
int data;


for(int i =0; i<n; i++)
{
a[i]= scanner.nextInt();
}

data = scanner.nextInt();

System.out.println("entered in array");

int l=0;
int h =n-1;

while (l<=h)
{
int mid = (l + h) /2;

if(data<a[mid])
{
h = mid-1;
}
else if(data>a[mid])
{
l = mid+1;
}
else
{
System.out.println("Found at position: "+mid);
return;
}
}

System.out.println("Not Found");




}
}
71 changes: 71 additions & 0 deletions ButterflyPattern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import java.util.Scanner;

public class ButterflyPattern {

public static void main(String [] args)
{
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int spaces;

for(int i=n-1; i>=0; i--)
{
spaces = i*2;

int rt = n-i;
int lt = n-i;

while(rt>0)
{
System.out.print("*");
rt--;
}

while(spaces>0)
{
System.out.print(" ");
spaces--;
}

while(lt>0)
{
System.out.print("*");
lt--;
}

System.out.println("");
}

for(int i=0; i<n; i++)
{
spaces = i*2;

int rt = n-i;
int lt = n-i;

while(rt>0)
{
System.out.print("*");
rt--;
}

while(spaces>0)
{
System.out.print(" ");
spaces--;
}

while(lt>0)
{
System.out.print("*");
lt--;
}

System.out.println("");
}




}
}

0 comments on commit 06f2bbe

Please sign in to comment.