Question: Java No hardco py or electronic notes, no communication with anyone other than the instructor du Problem 1 - Method Implementation Part A A prime
No hardco py or electronic notes, no communication with anyone other than the instructor du Problem 1 - Method Implementation Part A A prime number is an integer> 2 whose only factors are 1 and itself. 7: factors are 1 and 7, so 7 is prime 12: factors are 1, 2, 3,4, 6, and 12, so 12 is not prime Write a method public static boolean isprime(int n) t that returns true if n is prime, false if n is not prime. Hint: use a loop to check each integer i from 2 through n 1. For each i, check if i is a fact expression n%i=-0 to determine ifi is a factor of n. If any value i is a factor of n, immedia loop completes without finding a factor, return true. Part B The dot product of two vectors is defined as the sum of the products of all pairs of corres two vectors. Here's an example in pseudo-code (not Java) for two vectors of length 4: Vector a I3, 2, -1, 5] Vector b I 5, 3, 6, -2] Dot Product of a and b3*5 2 3 (-1)*65 (-2) =15 + 6-6-1? - 21 - 165 Write a Java method dotproduct0 to calculate and return the dot product of two vectors. one-dimensional integer arrays. Assume that the arrays have been correctly initialized an length. The algorithm is: Use a single loop to examine the elements of the arrays and use an accr Each time through the loop, calculate one term of the result and add it to the accumulator the end. Write code for the general case, do not assume arrays of length 4, the given exa intI] a [3, 2, -1, 5; int[] b [5, 3, 6, -2); int x- dotProduct (a, b);//x 5 in this case public static int dotproduct(int[] a, int[] b) Problem 2 - Guess-A-Number
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
