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...
Code in Java Create a queue class to store integers and implement following methods: 1) void...
Code in Java Create a queue class to store integers and implement following methods: 1) void enqueue(int num): This method will add an integer to the queue (end of the queue). 2) int dequeue(): This method will return the first item in the queue (First In First Out). 3) void display(): This method will display all items in the queue (First item will be displayed first). 4) Boolean isEmpty(): This method will check the queue and if it is empty,...
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.
Using the interface and class definitions below, write the headings of all of the methods which...
Using the interface and class definitions below, write the headings of all of the methods which still need to be defined in the class Class2. https://hastebin.com/kopejolila.java public interface Interface1 { public float method1(int i) ; } public interface Interface2 extends Interface1 { public int method2(int i) ; public void method3(int i) ; } public abstract class Class1 { public float method1(int anInt) { return anInt * 2.0f ; } public abstract void method3(Object anObject) ; public abstract void method4(int anInt)...
Write a Java class called Grades in a class file called Grades.java. 2. Grades reads from...
Write a Java class called Grades in a class file called Grades.java. 2. Grades reads from a text file containing a series of course grades (a value between 0.0 and 100.0) with one grade entry per line. However, the first line in the file is an integer value specifying how many grade entries are contained in the file. 3. The Grades class contains four static methods: a. A method called loadGrades() that opens the file, reads in the data and...
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 Java program that asks the user to enter an array of integers in the...
Write a Java program that asks the user to enter an array of integers in the main method. The program should prompt the user for the number of elements in the array and then the elements of the array. The program should then call a method named isSorted that accepts an array of and returns true if the list is in sorted (increasing) order and false otherwise. For example, if arrays named arr1 and arr2 store [10, 20, 30, 41,...
Java... Write a class named TestScores. The class constructor should accept an array of test scores...
Java... Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate the class in a program (create a Driver class in the same file). The program should ask the user to input the number of test scores to...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT