JAVA
1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a parameter. This method calculates and returns the largest even number in the list. If there are no even numbers in the array, the method should return 0. You can assume that the array is not empty.
For example:
| Test | Result |
|---|---|
int[] values = {1, 4, 5, 9};
System.out.println(getMaxEven(values)); |
4 |
System.out.println(getMaxEven(new int[]{1, 3, 5, 9})); |
0 |
public static int
---------------------------------------------------------------------------------
2.
Write a static method named noEven(values) that takes an array of integers as a parameter and returns true if all of the integers in the array are odd, and false otherwise. You can assume that the array is not empty and the method returns a boolean value.
For example:
| Test | Result |
|---|---|
System.out.println(noEven(new int[]{2, 3, 4, 5, 6})); |
false |
System.out.println(noEven(new int[]{1, 3, 5, 7})); |
true |
public static boolean
---------------------------------------------------------------------------------------
3.
Write a static method named repeats_exist(numbers) that takes an array of integers as a parameter and returns true if there are any repeated values in the array, and false if all of the values in the array are unique. Note: you can assume that the array is not empty and the method returns a boolean value.
For example:
| Test | Result |
|---|---|
System.out.println(repeats_exist(new int[]{2, 3, 4, 5, 6})); |
false |
System.out.println(repeats_exist(new int[]{2, 3, 4, 3, 6})); |
true |
public static boolean
------------------------------------------------------------------------------------------
These three are separate questions,please complete them one by one. Thx~
Answer 1) The code of this question is below:
public class Main
{
public static int getMaxEven(int [] arr){
int [] evenArray=new int[10];
int num;
for (int i = 0, j=0; i < arr.length; i++) {
if(arr[i] % 2 == 0){
evenArray[j] = arr[i];
j++;
}
}
int maxEven=0;
for (int i = 0; i < evenArray.length; i++){
if( evenArray[i] > maxEven )
maxEven=evenArray[i];
}
return maxEven;
}
public static void main(String[] args) {
int[] values1 = {1, 4, 5, 9};
System.out.println(getMaxEven(values1));
int[] values2 = {1, 3, 5, 9};
System.out.println(getMaxEven(values2));
}
}
CODE AND OUTPUT SCREENSHOT

Answer 2) The Code for this question is below:
public class Main
{
public static boolean noEven(int [] arr)
{
boolean odd=true;
for (int i = 0; i < arr.length; i++) {
if(arr[i] % 2 == 0){
odd=false;
}
}
return odd;
}
public static void main(String[] args) {
System.out.println(noEven(new
int[]{2, 3, 4, 5, 6}));
System.out.println(noEven(new int[]{1, 3, 5, 7}));
}
}
CODE AND OUTPUT SCREENSHOT

JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a...
JAVA~ 1. Write a static method named countOdd(my_array) that returns the number of odd integers in a given array. If there are no odd numbers in the array, the method should return 0. If the array is empty, the method should also return 0. For example: Test Result System.out.println(countOdd(new int[]{2, 3, 5, 6})); 2 System.out.println(countOdd(new int[]{2})); 0 System.out.println(countOdd(new int[]{})); 0 System.out.println(countOdd(new int[]{-7, 2, 3, 8, 6, 6, 75, 38, 3, 2})); 4 public static int ----------------------------------------------------------------------------------------------------------- 2. Write a static...
A java exercise please!
Write a static method named swapHavles that takes an ArrayList of integers as a a parameter and returns a new ArrayList that has every element in the second half of the original ArrayList swapped with every element in the first half of the original ArrayList. Note: • You can assume that the ArrayList passed to this method as a parameter always contains an even number of elements and will always contain at least two elements. For...
1) Write a public static method named printArray, that takes two arguments. The first argument is an Array of int and the second argument is a String. The method should print out a list of the values in the array, each separated by the value of the second argument. For example, given the following Array declaration and instantiation: int[] myArray = {1, 22, 333, 400, 5005, 9}; printArray(myArray, ", ") will print out 1, 22, 333, 400, 5005, 9 printArray(myArray,...
Write a java program that has a method called sameArrayBackwards. The method takes an array of integers, and checks if the numbers in the array are the same going forward as going backwards and will return a boolean (true or false) depending on the result. You can assume that there is at least one element in the array. Method Header: public static boolean sameArrayBackwards (int [] arr) You will test your method in the main method of your program by...
1. Write a static method named mode that takes an array of integers as a parameter and that returns the value that occurs most frequently in the array. Assume that the integers in the array appear in sorted order. For example, if a variable called list stores the following values: ist -3, 1, 4, 4, 4, 6, 7,8, 8, 8, 8, 9, 11, 11, 11, 12, 14, int 141i Then the call of mode (li array, appearing four times. st,...
in java Write a class named Palindrome.java and Write a method isPalindrome that takes an IntQueue as a parameter and that returns whether or not the numbers in the queue represent a palindrome (true if they do, false otherwise). A sequence of numbers is considered a palindrome if it is the same in reverse order. For example, suppose a Queue called q stores this sequence of values: front [3, 8, 17, 9, 17, 8, 3] back Then the following call:...
Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the Maximum of the 2 values Write a public static method named getMinOf2Ints that takes in 2 int arguments and returns the Minimum of the 2 values Write apublic static method named getMaxOf3Ints that takes in 3 int arguments and returns the Maximum of the 3 values Write a public static method named getMedianOf3Ints that takes in 3 int arguments and returns the Median Value...
/** * Write a method named outOfOrder that takes as a parameter an array of double and returns a value of type int. * This method will test the array for being out of order, meaning that the array violates the conditions: * array[0] <= arrayValues[0] <= arrayValues[2] <=... * * The method returns -1 if the elemnts are not out of order; otherwise , it returns the index of the first element of the array that is out of...
In JAVA: Write a method that reverses the array passed the argument and returns this array. Write a test program that prompts the user to enter ten numbers, invokes the method to reverse the numbers and display the numbers. Write a method that returns a new array by eliminating the duplicate values in the array using following method header: a. Public static int[] eliminateDuplicates(int list) b. Write a test program that reads in ten integers and invoke the method, the...
Ch. 09: Exclusive find in Array (Arrays, conditional, counter) Write a method that will receive an array of integers and an integer value as a parameter. The integer value received as the second parameter will be searched within the Array received as the other parameter. The method will return true if the value appears only once in the Array. Use the "documentation shown in the program as a guide". As an example, if the array received was the sequence of...