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