afiqakraam

arrayapp

Mar 23rd, 2021 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. /**
  2.  * Write a description of class arrayjava here.
  3.  *
  4.  * @afiqakraam
  5.  * @24/03/2021
  6.  */
  7. class arrayjava
  8. {
  9. public static void main (String[] args)
  10. {
  11.     long[]arr;
  12.     arr = new long[100];
  13.     int nElems = 0;
  14.     int j;
  15.     long searchKey;
  16.    
  17.     arr[0] = 77;
  18.     arr[1] = 99;
  19.     arr[2] = 44;
  20.     arr[3] = 55;
  21.     arr[4] = 22;
  22.     arr[5] = 88;
  23.     arr[6] = 11;
  24.     arr[7] = 00;
  25.     arr[8] = 66;
  26.     arr[9] = 33;
  27.     nElems = 10;
  28.     for(j=0; j<nElems; j++)
  29.         System.out.print(arr[j]+" ");
  30.     System.out.println("");
  31.    
  32.     searchKey = 66;
  33.     for(j=0; j<nElems; j++)
  34.         if(arr[j] == searchKey)
  35.         break;
  36.     if(j==nElems)
  37.         System.out.println("Can't find" + searchKey);
  38.     else
  39.         System.out.println("Found " + searchKey);
  40.        
  41.     searchKey = 55;
  42.     for(j=0; j<nElems; j++)
  43.     if(arr[j] == searchKey)
  44.         break;
  45.     for(int k=j; k<nElems; k++)
  46.         arr[k] = arr[k+1];
  47.     nElems--;
  48.    
  49.     for(j=0; j<nElems; j++)
  50.         System.out.println(arr[j] + " ");
  51.     System.out.println("");
  52.     }
  53. }
  54.  
Add Comment
Please, Sign In to add comment