Question

a. Write a method that receives (a reference to an array of integers and returns the number of odd values in the array that a
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#source code for first one:

import java.util.Scanner;

import java.lang.*;

class Sample{

public static int oddNumCount(int data[]){ //function declaration

int count=0;

for(int i=0;i<data.length;i++){ //iterate over each element in the array

if(data[i]%2==0){ //check element is odd or not

if(data[i]>65 || (data[i]>=20 && data[i]<=35 )){ //f element is odd than it chech condion

count=count+1; //increment the count value by 1

}

}

}

return count;

}

public static void main(String args[]){

int data[]={34,56,78,98,37,49,27,28,29,30}; //array intialization

int oddcount=oddNumCount(data); //call the method

System.out.println("Odd number count:"+oddcount); //print the oddcount in the array

}

}

#source code along with output:

1 2 3 4 5 6 7 8 import java.util.Scanner; import java.lang. *; class Sample { public static int oddNumCount(int data[]){ //fu

#second one source code such as formula expression:

import java.util.*;

import java.lang.*;

class Sample{

public static void main(String args[]){

double y=2,z=3; //here y and z values are initialized

double val=Math.pow(((Math.pow(y,3)-5)/Math.pow((1-Math.sqrt(z)),10)),2); //ecpression in single line

System.out.println("Value:"+val); //output the value

}

}

#source code along with output:

1 2 4 5 import java.util.*; import java.lang. *; class Sample { public static void main(String args[]) { double y=2, Z=3; //h

#if you have any doubt or more information needed comment below..i will respond as possible as soon..if you like give thumbs up...thanks..

Add a comment
Know the answer?
Add Answer to:
a. Write a method that receives (a reference to an array of integers and returns the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using java, write a method called findSmallestEven() that receives a 2-dimentional array of integers as a...

    Using java, write a method called findSmallestEven() that receives a 2-dimentional array of integers as a parameter and returns the smallest even number contained within it. [Note: Any hardcoded return value will not be accepted]

  • Write a java method that initializes an array of 10 random numbers integers between 1 and...

    Write a java method that initializes an array of 10 random numbers integers between 1 and 100 and a method that finds the largest odd number in the array of integers please.

  • In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are...

    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...

  • 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 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...

  • How to write a recursive method named lessThanKFirst that receives an array of integers a and...

    How to write a recursive method named lessThanKFirst that receives an array of integers a and an integer k and rearranges the integers in a in such a way that all integers that are smaller than k come before any integers that are greater than or equal to k. As an example, suppose that a and k are: int[] a  = {35, 12, 57, 28, 49, 100, 61, 73, 92, 27, 39, 83, 52}; int k = 73; Then, the following...

  • Write a function shuffle that takes an array of 20 integers and then shuffles the integers...

    Write a function shuffle that takes an array of 20 integers and then shuffles the integers using the following algorithm. For each element X of the array, generate a random number N between 0 and 19, inclusive. swap X with the element that corresponds to N.

  • 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 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...

  • Write a method called stdev that returns the standard deviation of an array of integers. Standard...

    Write a method called stdev that returns the standard deviation of an array of integers. Standard deviation is computed by taking the square root of the sum of the squares of the differences between each element and the mean, divided by one less than the number of elements. (It's just that simple!) More concisely and mathematically, the standard deviation of an array a is written as follows: stdev(a)=∑i=0a.length−1(a[ i ]−average(a)2)a.length−1 For example, if the array passed contains the values [1,...

  • In C, write a method that takes in an array of integers and returns its size....

    In C, write a method that takes in an array of integers and returns its size. Q9]Write a method that takes in an array of integers and returns it's sizel10 points

  • java code Write a method called reverse that takes an array of integers as an input...

    java code Write a method called reverse that takes an array of integers as an input and returns the same values in reverse order as the output. Test your method in the main.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT