Question

Using Java write all 4 methods in one class 1) Write a value-returning method that returns...

Using Java write all 4 methods in one class

1) Write a value-returning method that returns the number of elements in an integer array.

2) Write a void method that multiples by 2 all the elements in an array of float.

3) Write a value- returning method that returns the product of all elements in an integer array.

4) Write a method that returns the total # of elements greater or equal to 90 in an array of integers.

Homework Answers

Answer #1

Please upvote if you are able to understand this and if there is any query do mention it in the comment section.

CODE:

public class Main
{
   public static void main(String[] args) {
   int numInt[] = {102, 100, 60, 50, 120, 140, 80, 40};//creating an array of integer
   double numFLoat[] = {1.2, 2.2, 4.4, 5.78, 11.24, 98.22};//creating an array of double
   System.out.println("Number of elements in array: ");
System.out.println(numElems(numInt));//calling the method numElems
System.out.println("After multiplying the each element of array with 2: ");
mul(numFLoat);//calling the method numFloat
System.out.println("The product of all elements of array: ");
System.out.println(prod(numInt));//calling the method prod
System.out.println("Elements of array which are greater then or equal to 90");
System.out.println(total(numInt));//calling the method total
   }
   public static int numElems(int arr[]) {//method for finding length of integer array
       int len = arr.length;
       return len;
   }
   public static void mul(double arr[]) {//method for multiplying double array with 2
   double res = 0.0;
   for (int i = 0; i < arr.length; i++) {
   res = 2 * arr[i];
   System.out.println(res);
   }
   }
   public static int prod(int arr[]) {//method for product of each array element
   int res = 1;
   for (int i = 0; i < arr.length; i++) {
   res = res * arr[i];
   }
   return res;
   }
   public static int total(int arr[]) {//method for finding elements greater then 90
   for (int i = 0; i < arr.length; i++) {
   if(arr[i] >= 90) {
   System.out.println(arr[i]);//printing elements
   }
   }
return 0;
   }
}

OUTPUT:

Know the answer?
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
Similar Questions
Please answer quickly! Thank you. Java: Write a non-static method to be added to a class...
Please answer quickly! Thank you. Java: Write a non-static method to be added to a class that implements a singly linked list of integers. The method is called make_partition() and takes an integer x as input. The method should modify this list by moving all the elements less than x to the front of the list, and all the elements greater than x to the back of the list. It is not the important for the elements to be kept...
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice)....
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice). This program will read in three integers with Scanner, put the values in an array of int, and then print the product of the three values. Example output of the program is shown below, with user input shown in bold: Enter first integer: 3 Enter second integer: 4 Enter third integer: 5 Product: 60 More details about the method you need to write are...
Java Program Write a method called “fillMatrix” that takes two integers rows and cols and returns...
Java Program Write a method called “fillMatrix” that takes two integers rows and cols and returns a 2D array of integers of size rows x cols where the value of element [row][col] is row + col. Write a short program to test your method.
java Write a single Java statements to accomplish each of the following: a) Displaythevalueoftheseventhelementofcharacterarraych. b) Considering...
java Write a single Java statements to accomplish each of the following: a) Displaythevalueoftheseventhelementofcharacterarraych. b) Considering “Scanner in = new Scanner (System.in);”, input a value into element 5 of one-dimensional double array nums. c) Initialize each of the four elements of the one-dimensional integer array test to 7. d) Declare and create an array called table as a float array that has four rows and three columns. e) Considering the following ArrayList declaration, insert “test” at the fourth position (index...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns the index of the first occurance of the smallest value in the array. Your function must be able to process all the elements in the array. Create a function prototype and function definition (after the main function). Your main function should declare a 100 element integer array. Prompt the user for the number of integers to enter and then prompt the user for each...
IN JAVA: Write recursive method to return true if a given array has element equal to...
IN JAVA: Write recursive method to return true if a given array has element equal to employee emp, or returns false otherwise. Array can be empty or not. //PRECONDITION: Varible n denotes the number of occupied positions in the array and must be non-negative. Employee class has method getSalary() that returns employee's salary, // and it has method boolean equals(Employee emp) that accept an employee object and returns true if employee calling the equals method is equal as employee emp,...
IN JAVA Methods*: Calorie estimator Write a method ActivityCalories that takes a string indicating an activity...
IN JAVA Methods*: Calorie estimator Write a method ActivityCalories that takes a string indicating an activity (sit, walk, jog, bike, swim) and duration in minutes (integer), and returns the estimated calories expended (double). Calories per minute for a 150 lb person (source): sit: 1.4 walk: 5.4 run: 13.0 bike: 6.8 swim: 8.7 If the input is sit 2, the output is 2.8 Hints: Use an if-else statement to determine the calories per minute for the given activity. Return the calories...
Use Java: Also: Please include screenshots if possible. Create a class called AbstractStackTest. Write an abstract...
Use Java: Also: Please include screenshots if possible. Create a class called AbstractStackTest. Write an abstract method called makeStack that returns a Stack of Strings. Use the Stack interface as the return type, not a specific implementation! Write a class named NodeStackTest that extends your AbstractStackTest class. Implement the makeStack method to return a NodeStack. Repeat parts 1 and 2 for the Queue interface and the NodeQueue implementation. Write a new stack implementation, ArrayStack. It should be generic and use...
Write code in java Implement a method to build an AVL tree out of a sorted...
Write code in java Implement a method to build an AVL tree out of a sorted (ascending order) array of unique integers, with the fastest possible big O running time. You may implement private helper methods as necessary. If your code builds a tree that is other than an AVL tree, you will not get any credit. If your code builds an AVL tree, but is not the fastest big O implementation, you will get at most 12 points. You...
In this project, you will write a Java program that randomly generates annual salaries for professors...
In this project, you will write a Java program that randomly generates annual salaries for professors in the Computer Science and Engineering Technology (CSET) program at the University of Toledo in the past 10 years. Assume that there are five CSET professors. You should have a twodimensional array of values representing salaries. The first dimension represents the professors and the second dimension represents the years of the salaries. You should have a constructor that takes two integers representing the number...