Write a method that receives an array of integers as its parameter and modifies
ID: 3824572 • Letter: W
Question
Write a method that receives an array of integers as its parameter and modifies the contents of the array, by adding 1 the even values and subtracting 1 from the odd values. Example: If the array contained {37, 25, 19, 67, 82} then when the method returns the array contents would be {36, 24, 18, 66, 83}. Your method should work for an array of any size. Be sure to declare any local variable you may need. public static void modify (int[] list) {}//end reverse Write a method that receives an array of integers (o any length) a its parameter and returns true if the array contains no even number, otherwise it returns false. Example: If the array sent to it is {35, 17, 23} it returns true, the array is {29, 34, 13, 56) then it returns false. public static boolean hasNoEven(int[] arr) {//end method show the output from the following program fragment. public static void main(String[] args) {int[] arr = {34, 25, 67, 29, 12}; modify (arr); printArray(arr);}//end main Public static void modify (int[] arr) {for (int k = 0; kExplanation / Answer
Q4
public static void modify(int[] list){
for(int i=0;i<list.length;i++){
if(list[i]%2==0)
list[i] = list[i] + 1;
else
list[i] = list[i] - 1;
}
}
Q5 public static boolean hasNoEven(int[] arr){
boolean flag = true;
for(int i=0;i<arr.length;i++){
if(arr[i]%2==0){
flag = false;
break;
}
}
return flag;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.