Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * Write a description of class ArrayApp here.
- *
- * @author
- * @version
- */
- public class ArrayApp
- {
- public static void main(String [] args){
- // declares an Array
- long[]arr;
- arr = new long[100];
- int nElems = 0;
- arr[0] = 77;
- arr[1] = 99;
- arr[2] = 44;
- arr[3] = 55;
- arr[4] = 22;
- arr[5] = 88;
- arr[6] = 11;
- arr[7] = 00;
- arr[8] = 66;
- arr[9] = 33;
- nElems = 10;
- int j;
- long searchKey;
- // display items of Array
- for(j=0; j<nElems; j++)
- System.out.print(arr[j] +" ");
- System.out.println(" ");
- //search items
- searchKey = 66; // find item with key 66
- for(j=0; j<nElems; j++)
- if(arr[j] == searchKey)
- break;
- if(j == nElems)
- System.out.println("can't find" + searchKey);
- else
- System.out.println("Found" + searchKey);
- //delete items
- searchKey = 55; // delete item with key 55
- for(j=0; j<nElems; j++)
- if(arr[j] == searchKey)
- break;
- //deleting items
- for(int k=j; k<nElems; k++)
- arr[k] = arr[k+1];
- nElems--;
- //display items
- for(j=0; j<nElems; j++)
- System.out.print(arr[j]+" ");
- System.out.print(" ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment