-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc101d8
commit 06f2bbe
Showing
3 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
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,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]+" "); | ||
} | ||
|
||
|
||
} | ||
|
||
} |
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,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"); | ||
|
||
|
||
|
||
|
||
} | ||
} |
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,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(""); | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
} |