@@ -244,13 +244,12 @@ public static void main(String args[]){
244244 } 
245245} 
246246
247- */ 
247+ */ 
248248
249249// public class Arrays{ 
250250// public static void sumOfSubArray(int number []){ 
251251// int currSum = 0; 
252252// int maxSum = Integer.MIN_VALUE; 
253- 254253// for (int i = 0; i<number.length; i++){ 
255254// for (int j = i; j<number.length; j++){ 
256255// currSum=0; 
@@ -263,57 +262,116 @@ public static void main(String args[]){
263262// maxSum = currSum; 
264263// } 
265264// } 
266- 267265// System.out.println(); 
268266// } 
269267// System.out.print("The maximum Sum is: " + maxSum); 
270268// } 
271- 272269// public static void main(String args[]){ 
273270// int number[] = {1,-2,6,-1,3} ; 
274271// sumOfSubArray(number); 
275272// } 
276- 277273// } 
278- 279274// BINARY SEARCH 
280275// plan: V-mid, start, end 
281276// I=key, array number 
282277// p=mid=key;mid<key,strt=mid+1; mid>key,end=mid-1 
283278// 0=i i.e key 
279+ // public class Arrays{ 
280+ // public static int binarySearch(int number[], int key){ 
281+ // for(int i=0; i<number.length; i++){ 
282+ // int start = 0; 
283+ // int end = number.length-1; 
284+ // while(start<=end){ 
285+ // int mid=(start+end)/2; 
286+ // if(number[mid]==key){ 
287+ // return mid; 
288+ // } 
289+ // else if(number[mid]<key){ 
290+ // start=mid+1; 
291+ // } 
292+ // else if(number[mid]>key){ 
293+ // end=mid-1; 
294+ // } 
295+ // } 
296+ // } 
297+ // return -1; 
298+ // } 
299+ // public static void main(String args[]){ 
300+ // int number[]={2,4,6,7,8,9,10,15,19,20}; 
301+ // int key=20; 
302+ // int result=binarySearch(number, key); 
303+ // if (result==-1){ 
304+ // System.out.print("The no is not in array"); 
305+ // } 
306+ // else{ 
307+ // System.out.print("The no is at index: " + binarySearch(number,key)); 
308+ // } 
309+ // } 
310+ // } 
311+ // import java.util.*; 
312+ // public class Arrays{ 
313+ // public static void main(String args[]){ 
314+ // int number[]=new int[5]; 
315+ // System.out.println("ENter the elements of array: "); 
316+ // Scanner sc=new Scanner(System.in); 
317+ // number[0]=sc.nextInt(); 
318+ // number[1]=sc.nextInt(); 
319+ // number[2]=sc.nextInt(); 
320+ // number[3]=sc.nextInt(); 
321+ // number[4]=sc.nextInt(); 
322+ // System.out.print("number[] = "+number); 
323+ // } 
324+ // } 
325+ // public class Arrays{ 
326+ // public static void main(String args[]){ 
327+ // int number[]={22,45,85,965,7544,78546}; 
328+ // int lar = Integer.MIN_VALUE; 
329+ // for(int i=1; i<number.length; i++){  
330+ // if (number[i]>lar){ 
331+ // lar=number[i]; 
332+ // } 
333+ // } 
334+ // System.out.print("largest number in the array is:"+lar); 
335+ // } 
336+ // } 
337+ // p/lan: v-start,end,temp,i,j,swap 
338+ //  
339+ public  class  Arrays  {
284340
285- public  class  Arrays {
286-  public  static  int  binarySearch (int  number [], int  key ){
287-  for (int  i =0 ; i <number .length ; i ++){
288-  int  start  = 0 ;
289-  int  end  = number .length -1 ;
341+  public  static  void  reverseArray (int  number []) {
342+  int  start  = 0 ;
343+  int  end  = number .length  - 1 ;
344+ 345+  while  (start  < end ) {
346+  int  temp  = number [end ];
347+  number [end ] = number [start ];
348+  number [start ] = temp ;
349+  start ++;
350+  end --;
351+  }
290352
291-  while (start <=end ){
292-  int  mid =(start +end )/2 ;
293-  if (number [mid ]==key ){
294-  return  mid ;
295-  }
296-  else  if (number [mid ]<key ){
297-  start =mid +1 ;
298-  }
299-  else  if (number [mid ]>key ){
300-  end =mid -1 ;
301-  }
353+  }
354+ 355+  public  static  void  printPairs (int  number []){
356+  int  tp  = 0 ;
357+  for (int  i =0 ; i <number .length ; i ++){
358+  int  curr  = number [i ];
359+  for (int  j =i +1 ; j <number .length ; j ++){
360+  System .out .print ("("  + curr  + ","  + number [j ] + ")" );
361+  tp ++;
302362 }
303- 363+  System . out . println (); 
304364 }
305-  return  - 1 ;
365+  System . out . print ( "Total no of pairs: "  +  tp ) ;
306366 }
307-  public  static  void  main (String  args []){
308-  int  number []={2 ,4 ,6 ,7 ,8 ,9 ,10 ,15 ,19 ,20 };
309-  int  key =20 ;
310-  int  result =binarySearch (number , key );
311367
312-  if  (result ==-1 ){
313-  System .out .print ("The no is not in array" );
314-  }
315-  else {
316-  System .out .print ("The no is at index: "  + binarySearch (number ,key ));
317-  }
368+  public  static  void  main (String  args []) {
369+  int  number [] = {2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 };
370+  // reverseArray(number); 
371+  // for (int i = 0; i < number.length; i++) { 
372+  // System.out.print(+number[i] + " "); 
373+  // } 
374+ 375+  printPairs (number );
318376 }
319- }
377+ }
0 commit comments