Skip to content

Commit 8ecbe77

Browse files
Update 1D Array
1 parent dd05680 commit 8ecbe77

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

1D Array

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,31 @@ public class Main
133133
}
134134

135135

136+
/*Given a sorted array A and a target value B, return the index if the target is found. If not, print the index where
137+
it would be if it were inserted in order.
138+
First line given is an integer N, denoting the size of array A. Second line contains N integers - the elements of array A.
139+
Third line given is integer B.
140+
example 4 [3 7 12 44] 11 output 2(index number) */
141+
142+
import java.util.*;
143+
public class Main
144+
{
145+
public static void main(String[] args) {
146+
Scanner sc = new Scanner(System.in);
147+
int n =sc.nextInt();
148+
int a[] = new int[n];
149+
for(int i=0;i<n;i++){
150+
a[i]=sc.nextInt();
151+
152+
}
153+
int k = sc.nextInt();
154+
for(int i=0;i<n;i++){
155+
if(a[i]>=k){
156+
System.out.println(i);
157+
break;
158+
}
159+
160+
}
161+
}
162+
}
163+

0 commit comments

Comments
 (0)