原帖由 毛毛小子 于 2009-1-13 09:11 PM 发表
想请教下,就是那个arr.insert()是属于array一部分?什么用途的?
复制代码
- class HighArray
- {
- private long[] a;
- private int nElems;
- //---------------------------------------------------------
- public HighArray(int max)
- {
- a = new long[max];
- nElems = 0;
- }
- //---------------------------------------------------------
- public boolean find(long searchKey)
- {
- int j;
- for (j=0; j<nElems;j++)
- if(a[j]==searchKey)
- break;
- if (j == nElems)
- return false;
- else
- return true;
- }
- //--------------------------------------------------------
- public void [color=Red][b]insert[/b][/color](long value)
- {
- a[nElems] = value;
- nElems++;
- }
- //--------------------------------------------------------
- public boolean delete(long value)
- {
- int j;
- for(j=0; j<nElems; j++)
- if(value ==a[j])
- break;
- if(j==nElems)
- return false;
- else
- {
- for(int k=j; k<nElems; k++)
- a[k] = a[k+1];
- nElems--;
- return true;
- }
- }
- //--------------------------------------------------------
- public void display()
- {
- for(int j=0; j<nElems; j++)
- System.out.print(a[j]+" ");
- System.out.print(" ");
- }
- //--------------------------------------------------------
- }
复制代码
- class HighArrayApp
- {
- public static void main(String[] args)
- {
- int maxSize= 100;
- HighArray arr;
- arr = new HighArray(maxSize);
- arr.[b][color=Red]insert[/color][/b](77);
- arr.insert(99);
- arr.insert(44);
- arr.insert(55);
- arr.insert(22);
- arr.insert(88);
- arr.insert(11);
- arr.insert(00);
- arr.insert(66);
- arr.insert(33);
- arr.display();
- int searchKey = 1000;
- if(arr.find(searchKey))
- System.out.println("Found " +searchKey);
- else
- System.out.println("Can't find "+searchKey);
- arr.display();
- }
- }
原帖由 宅男-兜着走 于 2009-1-13 10:02 PM 发表
public boolean delete(long value) 这句我不是很明白,retuen true还有false 的是怎样的。
原帖由 毛毛小子 于 2009-1-13 11:00 PM 发表
我想请教下JAVA:
那个creating object :
ABC myABC;
myABC = new ABC();
怎样运用em0010
原帖由 宅男-兜着走 于 2009-1-14 01:12 PM 发表
1. 我请问,如果 在Method 里面放 break; 有效果的吗?
2. 请问, system.exit(0), 还有 break; 的分别怎么算?
3.当寻找不到 user 要求的var 的时候,要暂停 method, 是你你会怎么写?没switch case 的时候。
原帖由 宅男-兜着走 于 2009-1-14 01:58 PM 发表
问题3表达错误。
我的意思是说,昨天我在 void method 里找到值,然后要退出循环,然后 compile 不给。
我是用 break;。 实际上是可以做到的对不?
欢迎光临 JBTALKS.CC (https://www.jbtalks.cc/) | Powered by Discuz! X2.5 |