Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class/static method that takes an array of ints as a parameter and retur

ID: 3632831 • Letter: W

Question

Write a class/static method that takes an array of ints as a parameter and returns true if the number of positive values in the array is greater than then number of negative values, and false otherwise.

Write a class/static method that takes an array of ints as a parameter and returns an array of booleans (of the same length as the parameter array). For each element in the parameter array whose value is even, the corresponding element of the returned array will be assigned the value true; all the other elements of the returned array will be assigned the value false.

Write a class/static method that takes an array of Strings as a parameter and returns an array of Strings (of the same length as the parameter array) containing the elements of the parameter array truncated to the first 5 characters (or not truncated if not longer than 5 characters).

Explanation / Answer

public static boolean posgneg(int[] a)

{

int pos=0,neg=0;

for(int i=0; i<a.length(); i++)

{

if(a[i]>0) pos++;

else neg++;

}

if(pos>neg) return true;

return false;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote