Question: Please write in JAVA import static org.junit.Assert.*; import org.junit.After; import org.junit.Before; import org.junit.Test; import java.util.Random; import java.io.*; import java.util.*; import java.util.zip.CRC32; public class P2J9Test {
Please write in JAVA
import static org.junit.Assert.*; import org.junit.After; import org.junit.Before; import org.junit.Test; import java.util.Random;
import java.io.*; import java.util.*; import java.util.zip.CRC32;
public class P2J9Test {
// You can use this utility method to print true positions of the boolean[]. private void printTrues(boolean[] a) { for(int i = 0; i
make sure the code can pass the test, will give up the vote. Thanks
The two problems in this lab produce results of type boolean[], arrays whose each element is a truth value. Since these individual bits can be packed eight per each memory byte, the storage of these arrays as bit vectors will be as compact as can be, with no bit or byte left wasted in taking these truth bombs to the enemy! Create the class named P2J9 in your Blue) labs project, and there the following two methods that each solve a problem that involves squares of positive integers. Given this upper limit n as parameter, the result of both methods is a boolean[] array of n elements that reveals the answers to that problem for all natural numbers less than n in one swoop. public static boolean[] sumoftwoDistinctSquares(int n) Determines which natural numbers can be expressed in the form a2 + b2 so that a and b are two distinct positive integers. In the boolean array returned as result, the i:th element should be true if and only if such a breakdown is possible. The infinite sequence of positive integers that allow such breakdown begins with 5, 10, 13, 17, 20, 25, 26, 29, 34, 37, 40, 41, 45, 50, 52, ... You may have previously seen a version of this problem where the breakdown to two distinct squares was done separately for one number at the time. Given n, the question asked you to find positive integers a and b whose squares add up to n. However, since we are dealing with values in bulk, perhaps rather than looping through each n and find positive integers a and b whose squares add up to n separately for each n, it would be more productive to loop through all relevant pairs of a and b, and see which values of n can be built from those pairs... The two problems in this lab produce results of type boolean[], arrays whose each element is a truth value. Since these individual bits can be packed eight per each memory byte, the storage of these arrays as bit vectors will be as compact as can be, with no bit or byte left wasted in taking these truth bombs to the enemy! Create the class named P2J9 in your Blue) labs project, and there the following two methods that each solve a problem that involves squares of positive integers. Given this upper limit n as parameter, the result of both methods is a boolean[] array of n elements that reveals the answers to that problem for all natural numbers less than n in one swoop. public static boolean[] sumoftwoDistinctSquares(int n) Determines which natural numbers can be expressed in the form a2 + b2 so that a and b are two distinct positive integers. In the boolean array returned as result, the i:th element should be true if and only if such a breakdown is possible. The infinite sequence of positive integers that allow such breakdown begins with 5, 10, 13, 17, 20, 25, 26, 29, 34, 37, 40, 41, 45, 50, 52, ... You may have previously seen a version of this problem where the breakdown to two distinct squares was done separately for one number at the time. Given n, the question asked you to find positive integers a and b whose squares add up to n. However, since we are dealing with values in bulk, perhaps rather than looping through each n and find positive integers a and b whose squares add up to n separately for each n, it would be more productive to loop through all relevant pairs of a and b, and see which values of n can be built from those pairs
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
