Write a Java method that takes an array of type int and returns a boolean value....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a Java method that takes an array of type int and returns a boolean value. The method returns true if the power sum of the negative elements of the parameter array is larger than the power sum of the positive elements, otherwise, the method returns false. The method's header is as follows. public static boolean compare (int[] x) Sample run int[] x = {1, 3, 4, -10}; // power sum of positive elements = 1*1 + 3*3 + 4*4 = 26 // power sum of negative elements = -10*-10 = 100 boolean b = compare (x); int[] x = {1, 3, 4); // power sum of positive elements = 1*1 + 3*3 + 4*4 = 26 // power sum of negative elements = 0 boolean b compare (x); int[] x = {3, 4, -5}; // power sum of positive elements = 3*3 + 4*4 = 25 // power sum of negative elements = -5*-5 = 25 boolean b compare (x); Result true false false Write a Java method that takes an array of type int and returns a boolean value. The method returns true if the power sum of the negative elements of the parameter array is larger than the power sum of the positive elements, otherwise, the method returns false. The method's header is as follows. public static boolean compare (int[] x) Sample run int[] x = {1, 3, 4, -10}; // power sum of positive elements = 1*1 + 3*3 + 4*4 = 26 // power sum of negative elements = -10*-10 = 100 boolean b = compare (x); int[] x = {1, 3, 4); // power sum of positive elements = 1*1 + 3*3 + 4*4 = 26 // power sum of negative elements = 0 boolean b compare (x); int[] x = {3, 4, -5}; // power sum of positive elements = 3*3 + 4*4 = 25 // power sum of negative elements = -5*-5 = 25 boolean b compare (x); Result true false false
Expert Answer:
Answer rating: 100% (QA)
public static boolean compareint x Initialize the power sums of positive and negative element... View the full answer
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
Write an assembly language program that does the following: Create an encryption key consisting of multiple characters. Use this key to encrypt and decrypt the plaintext by XOR-ing each character of...
-
Maria is in the 25% tax bracket. Steve is in the 15% tax bracket. They each itemize their deductions and pay $10,000 in mortgage interest during the year. Compare. their true costs for mortgage...
-
Interpret the macroeconomic data of the economy described by the fol- lowing table. Are economic developments compatible with Phillis curve? What is real interest rate? What can we say about the...
-
How might a shareholders agreement influence a companys financial report-ing objectives?
-
Suppose that P = 3.78x2 + 1.5y2 - 0.09x3 - 0.01y3 tons is the production function for a product with x units of one input and y units of a second input. Find the values of x and y that will maximize...
-
For the year ending March 31, 20Y5, Omega Systems Inc. reported net income of $105,450 and paid dividends of $7,500. Comparative balance sheets as of March 31, 20Y5 and 20Y4, are as follows:...
-
Prepare a list of possible objections to the products, and your responses to them.
-
Mandy Knox is the new manager of the materials storeroom for Timken Manufacturing. Mandy has been asked to estimate future monthly purchase costs for part # 696, used in two of Timkens products....
-
Many people probably think that those who are good at math always do exact calculations, but estimation is actually a really useful tool, especially when it comes to things like percent discount....
-
John and Sandy Ferguson got married eight years ago and have a seven-year-old daughter, Samantha. In 2020, John worked as a computer technician at a local university earning a salary of $152,000, and...
-
Heights Ltd acquired all the shares in Salitex Ltd on the 31st December 2014 at a cost of UGX 100,000,000. The information below provides the statements of Financial Position for both companies on...
-
The toy race track in Figure P11.4 has three lanes, and cars cannot change lanes. The centerlines of any two adjacent lanes are 100 mm apart, and the innermost lane has a radius of 1.00 m. (a) If...
-
If you were to throw a penny horizontally as hard as you could from the top floor of the Empire State Building, about how far from the basc would it land?
-
A salad spinner (Figure P11.11) is used to dry lettuce that has been washed. What physics is going on as the spinner does its job? Data from Figure P11.11
-
You have inherited property in Vermont that would make an excellent ski resort. One of the slopes has a cliff on the other side of the hill, and this gives you a moneysaving idea. Instead of a chair...
-
Describe the properties of two vectors for which (a) \(\vec{A}+\vec{B}=\vec{A}-\vec{B}\) and (b) \(|\vec{A}|+|\vec{B}|=|\vec{A}+\vec{B}| \)
-
The average U.S child spends as much time watching television as attending school or interacting with parents A. True B. False
-
Is it a breach of fiduciary duty for a director of a real estate investment trust (REIT) negotiating a joint venture on behalf of the REIT with another director for the development of a portfolio of...
-
Suppose we can buy a chocolate bar from the vending machine for $1 each. Inside every chocolate bar is a coupon. We can redeem six coupons for one chocolate bar from the machine. This means that once...
-
Find the documentation for the Java Class Library on the Oracle Web site. (At this writing, the link to this documentation is https://docs.oracle.com/javase/8/docs/api/.) Then find the description...
-
Modify Programming Project 5 from Chapter 2 to check the validity of input data. Valid input is no less than 25 cents, no more than 100 cents, and an integer multiple of 5 cents. Compute the change...
-
How closely related do you believe language and thought to be? During the production of Chapter 3 in this book, the authors and editors debated whether we should use the word "autistics" or the...
-
When did human language originate?
-
Describe American styles of nonverbal communication. Are there different styles of nonverbal communication in different areas of the United States?
Study smarter with the SolutionInn App