package test2;
//import java.util.*;
public class Test {
private int array[];
private int nElements;
public Test(int max){
array = new int[max];
nElements = 0;
}
public boolean insert(int value){
if(nElements < array.length){
array[nElements] = value;
nElements ++;
return true;
}
else{
System.out.println("insert failed");
return false;
}
}// insert
public void delete(int value){
for(int i=0;i<nElements;i++){
if(value == array[i]){
for(int j=i;j<nElements-1;j++){
array[j] = array[j+1];
}//for
nElements--;
return;
}//if
else if((i+1) == nElements){
System.out.println("delete failed ,can not find :"+value);
return;
}
}//for
}//delete
public void find(int value){
for(int i = 0; i<nElements;i++){
if(value == array[i]){
System.out.println("
Java 中对数组进行封装
最新推荐文章于 2024-01-18 20:20:01 发布