快考试了,老师出的复习提纲,我实在是太菜,不会做,所以来这里请教高人。谢谢
两道题目,每道题目五个空。
两道题目,我都只会做空1,
第一题的空1是填“test”;第二题的空1是填“bubblesort”
其他的看不太懂。谢谢题目一:本程序实现查找并打印1到100之间所有素数的功能。(素数即只
能被1和本身整除的数)
public class test{
空1{
int lowLimit=1;
int upLimit=100;
空2;
}
boolean isPrime(int n){
int j = 0;
boolean result ;
result = false;
if (n%2!=0){
j=3;
result=true;
while(j<=Math.sqrt(n)){
if(n%j==0){
空3;
break;
}
j+=2;
}
}
return result;
}
public void find(int lowLimit,int upLimit){
int i,k=0,p=0;
boolean f;
for(i=lowLimit;i<upLimit;i++){
f=空4;
if (f){
System.out.println(Integer.toString(i));
}
}
}
         空5{
test temp = new test();
}
}题目二:本程序创建了一个用于冒泡排序的类,需要使用该类时,将待排序的数组作为参数传给bubblesort类,即可获得排序后的输出
class bubblesort{
    空1{
        sort(a);   
    }
    public void sort(int a[]){
int length =空2;
boolean isNoSwap = false;   
while( ! isNoSwap ){
             空3;
for ( int i=0;i<length-1;i++ )     
if ( a[i]>a[i+1] ){
int temp=a[i];
a[i]=a[i+1];
空4;
isNoSwap=false;    

}
       for ( int i=0;i<length;i++ )
System.out.println(a[i]+""); 
    }
}public class test{
public static void main(String args[]){
int a[] = { 1, -1, 2, 5, -2 }; 
bubblesort temp = 空5;
}
}

解决方案 »

  1.   

    没仔细看,大致看了一下第一题:
    1: test
    2: ( I don't know )
    3: result = false;
    4: isPrime(i)
    5: public static void main(String[] args)
      

  2.   

    你会的两空似乎都填错了第一题空1应该是test()
    第二题空1应该是bubblesort(int[] a)自己加油吧
      

  3.   

    第二题:
    1: bubblesort
    2: a.length
    3: isNoSwap = true; // ?
    4: a[i+1]=temp;
    5: new bubblesort()
      

  4.   

    经测试:
    一、
    1: public test()
    2: find(lowLimit,upLimit)
    3: result = false
    4: f=isPrime(i)
    5: public static void main(String[] args)二、
    1: public bubblesort(int[] a)
    2: a.length
    3: isNoSwap = true;
    4: a[i+1]=temp
    5: new bubblesort(a)呵呵,我错了4个!!!晕!!!
      

  5.   

    这个不对不满足题目
    二、
    1: public bubblesort(int[] a)
    2: a.length
    3: isNoSwap = true;
    4: a[i+1]=temp
    5: new bubblesort(a)
    应该是:
    二、
    1: public bubblesort(int[] a)
    2: a.length+1
    3: if (length==1 ) break;length=length-1;
    4: a[i+1]=temp
    5: new bubblesort(a)