• Welcome to ComeFromChina Community (CFC中文网)! We are the largest Chinese Canadian community forum in Ottawa. Please to participate in discussions, post topics, view images, and access full community features. Join us today! 欢迎来到CFC中文网。请登录以参与讨论、发布主题并查看图片。

可不可以帮忙解释一下comp1005 ass.#2

难啊,难啊....怎么总是觉得上课讲的东西和assignment相差这么大!!!~~~~>_<~~~~
 
这种ASSIGNMENT..MARK过去就批评过,说完全不适合.

出题的人应该是数学高手,例如"轩爷"之类的人.
 
pseudo code有问题

那个
temp=divisor+1
while (bool[temp]=F) do {temp++; divisor=temp+1}

是多余的

divisor++;就可以了
多谢cola的code
 
Question1:
private static void displayPrimes(int n, int[] primes){
{
//as requested, n shouldnt smaller than 0
//primes's length should greater than 0
//exit the program if any of those requests have been reached
}
{
//set a tag for print out
//load the whole primes array[for loop for example]
//print out them and tag++
//when tag reach 10, break to another line
}
}

private static int[] computePrimes(int n){
//as gave out mentioned, make a new boolean array
//set all value to true[use for loop for example]

//get the root by using Math.sqrt(n)

//start the index at 2

//index should same than the root [use while loop for example]
{
{[you can use for loop here]
//find those indices of the index but except those indexes
//set them to false
}
}
//creat a new index[ old index++ for example]
}

//make new array that is enough to contain those values, n is enough for sure

//use something as a tag
{
//only use those true array values and it should starts from 2
//set the return array[you can use the tag, return[tag] for example
tag++

}
//return the array
}

public static void main(String args[]){
System.out.println("The following is the output of a test run:\n" +
"(user input is indicated with italics)\n");
System.out.println("Enter an integer. "+
"This program will output a list of primes less than this number.");

//get a value from client, use the given keyboard class

System.out.println("The primes less than 1000 are\n");
//call the method and get the integer array
//display the result
}
}
 
最多2个人了,再多我就帮不了了,我也有作业的,别累我,多谢合作
 
后退
顶部
首页 论坛
消息
我的