Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class LowArray here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- class LowArray
- {
- private long[] a;
- public LowArray(int size){
- a = new long[size];
- }
- public void setElem(int index, long value){
- a[index] = value;
- }
- public long getElem(int index){
- return a[index];
- }
- }
- public class LowArrayApp
- {
- public static void main(String [] args){
- // declares an Array
- LowArray arr;
- arr = new LowArray(100);
- int nElems=0;
- int j;
- arr.setElem(0,77);
- arr.setElem(1,99);
- arr.setElem(2,44);
- arr.setElem(3,55);
- arr.setElem(4,22);
- arr.setElem(5,88);
- arr.setElem(6,11);
- arr.setElem(7,66);
- arr.setElem(8,0);
- arr.setElem(9,33);
- nElems = 10;
- //Display items of Array
- for(j=0; j<nElems; j++)
- System.out.print(arr.getElem(j)+ " ");
- System.out.println(" ");
- //Search items
- int searchKey = 26;
- for(j=0; j<nElems; j++)
- if(arr.getElem(j) == searchKey)
- break;
- if(j == nElems)
- System.out.println("Can't find "+ searchKey);
- else
- System.out.println("Found "+ searchKey);
- //Delete Items
- for(j=0; j<nElems; j++) //search items
- if(arr.getElem(j) == 55)
- break;
- //deleting items
- for(int k=j; k<nElems; k++)
- arr.setElem(k,arr.getElem(k+1));
- nElems--;
- //Display items
- for(j=0; j<nElems; j++)
- System.out.print(arr.getElem(j)+" ");
- System.out.println(" ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement