comp1005 ass.#2 的解释和做法

苦逼热狗

路边通讯社社长
VIP
注册
2002-10-12
消息
47,112
荣誉分数
2,376
声望点数
393
cola的pseudocode
-----------------
Question 1

input n
setup array of bool[n] with default values of all Ts
***
divisor = 2

while (divisor <= floor(root(n))) do
{

for i=(divisor+1) to n {
___if i mod divisor = 0 { bool=F }
}
temp=divisor+1
while (bool[temp]=F) do {temp++; divisor=temp+1}

}
***
print all the index of bool[n] such that bool[n]=T
--------------------
关于floor(root(n))的解释是
floor和ceiling,floor()舍尾,ceil() rounds up
root(n)求sqrt,JAVA中我们可以用Math.sqrt(x)
 
我的解释,base on cola的pseudocode以及assignment requirement

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
}
}
 
谁有空帮他们一起看看吧
总不能每次都-______-有这么几个无辜的羊羔受伤伤害吧。例如me:crying:

Question 2 to Be Continue....
 
写到哪里了?
Question 2,3来点hint
 
最初由 BloodHound 发布
写到哪里了?
Question 2,3来点hint
】你以前是不是staryang论坛得
看你卖得软件很想现在team里面得那些
以前我们得站ftp好强 现在那样得不多了
 
呵呵,不是那个论坛的

还会有更多的东西,不过机子没空间了
只会找我喜欢的下
 
I quit, cant take this anymore
Good Luck to you guys.
 
后退
顶部