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 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
Screenshot of code1:

output:




code:
import java.util.Scanner;
class Main
{
public static void main(String args[])
{
int n,i;
Scanner sc=new Scanner(System.in);
System.out.print("Enter number of elements in array: ");
n=sc.nextInt();
if(n==0)
{
System.out.print("No of odd elements in array is:
"+countOdd(a,n));
return;
}
int a[]=new int[n];
System.out.print("Enter elements in array: ");
for(i=0;i<n;i++)
a[i]=sc.nextInt();
System.out.print("No of odd elements in array is:
"+countOdd(a,n));
}
static int countOdd(int a[],int n)
{
int i,c;
c=0;
for(i=0;i<n;i++)
{
if(a[i]%2!=0)
c++;
}
return c;
}
}
Screenshot of code2:

output:


code:
import java.util.Scanner;
class Main
{
public static void main(String args[])
{
int n,i;
Scanner sc=new Scanner(System.in);
System.out.print("Enter number of elements in array: ");
n=sc.nextInt();
int a[]=new int[n];
System.out.print("Enter elements in array: ");
for(i=0;i<n;i++)
a[i]=sc.nextInt();
System.out.print("Result is: "+repeats_exist(a,n));
}
static boolean repeats_exist(int a[],int n)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]==a[j])
return true;
}
}
return false;
}
}
//please upvote.
JAVA~ 1. Write a static method named countOdd(my_array) that returns the number of odd integers in...
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...
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...
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...
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...
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,...
Java 1. Write a getCount method in the IntArrayWorker class that returns the count of the number of times a passed integer value is found in the matrix. There is already a method to test this in IntArrayWorkerTester. Just uncomment the method testGetCount() and the call to it in the main method of IntArrayWorkerTester. 2. Write a getLargest method in the IntArrayWorker class that returns the largest value in the matrix. There is already a method to test this in...
In Java*
Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...
Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...
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 getCount method in the IntArrayWorker class that returns the count of the number of times a passed integer value is found in the matrix. There is already a method to test this in IntArrayWorkerTester. Just uncomment the method testGetCount() and the call to it in the main method of IntArrayWorkerTester. Write a getLargest method in the IntArrayWorker class that returns the largest value in the matrix. There is already a method to test this in IntArrayWorkerTester. Just uncomment...