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
}
}