Question

Write a Java method to print the maximum and minimum value of an array containing elements...

Write a Java method to print the maximum and minimum value of an array containing elements [7,20,29,0,4,30,24,100]

Homework Answers

Answer #1

JAVA CODE :

import java.util.*;

public class Main
{
public static void printMaxiMini(int a[])
{
Arrays.sort(a); // sorts the array
System.out.println("Minimum : " + a[0]); // print minimum value
System.out.println("Maximum : " + a[a.length - 1]); // print maximum value
}
   public static void main(String[] args) {
       int a[] = {7, 20, 29, 0, 4, 30, 24, 100}; // initialize the array elements
       printMaxiMini(a); // call printMaxiMini
   }
}

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
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.
Write a program to determine the minimum element in an array of ten elements. The program...
Write a program to determine the minimum element in an array of ten elements. The program should have the following: 1. Class Name as ArrayProcessing. The main method should create an array of size 10 2. There should be two methods besides the main method in the class namely inputArray and MinimumElement 3. InputArray method should assign the ten elements in the array. Use scanner to input these elements. The array of 10 numbers in the method "InputArray" should be...
Write a Java part code to do the following   : ** Suppose a file called infile stored...
Write a Java part code to do the following   : ** Suppose a file called infile stored in drive D: ,filled with five integers(1000,200,3030,40 and 500) Read  the integers from infile then store them in array called ar[] and print it elements. Method called search( ) to print the location of   value 500. Method called sort() to sort array elements. Build another file called outfile in drive D: to save the sorted array elements . Note : Use ArrayIndexOutOfBoundsException when you use array...
THIS IS JAVA PROGRAMMING Write a method that finds the shortest word in an array of...
THIS IS JAVA PROGRAMMING Write a method that finds the shortest word in an array of String values and returns the length, in characters, of that word. The method should use the following header. public static int minLength(String[] array) Write a test program that prompts the user to enter ten strings, store them in an array and invokes this method to return the shortest length, and displays that value. (A near complete program can be found attached to the dropbox)
Java Lab Assignment Write a method named findMax. The method will take an array of doubles...
Java Lab Assignment Write a method named findMax. The method will take an array of doubles as an argument, and it will return the largest value in the array. (Note, you will have to create a new array of doubles) . method must be well documented using JavaDoc, example: /** * The find method checks if the target in the array * @param String [] a - array of Strings * @param String t - value to be searched for...
Java Lab Assignment Write a method called convertToString. The method will take an array of chars...
Java Lab Assignment Write a method called convertToString. The method will take an array of chars as an argument and it will return a String. Each index of the array will be part of the each index of the String. method must be well documented using JavaDoc, example: /** * The find method checks if the target in the array * @param String [] a - array of Strings * @param String t - value to be searched for *...
Write a program that uses an array of integers initialized to whatever values you wish. Write...
Write a program that uses an array of integers initialized to whatever values you wish. Write a methods to calculate and return the minimum and a method to calculate and return the maximum value in the array. Write an additional method that accepts the array as a parameter and then creates and returns a new array with all the same values as the original plus 10. (num +=10) In Java
The elements of an integer-valued array can be set to 0 (i.e., the array can be...
The elements of an integer-valued array can be set to 0 (i.e., the array can be cleared) recursively as follows: An array of size 0 is already cleared; Otherwise, set the last of the uncleared elements of the array to 0, and clear the rest of the array Write a void method named clear that accepts an integer array, and the number of elements in the array and sets the elements of the array to 0. Need it to be...
This is JAVA Write the method findMin that will return the smallest number in an array...
This is JAVA Write the method findMin that will return the smallest number in an array of integers. Examples: findMin({29,2,32,12}) -> 2 public int findMin(int[] numbers) {    }
Write a method name maxElement, which returns the largest value in an array that is passed...
Write a method name maxElement, which returns the largest value in an array that is passed as an argument. The method must use recursion to find the largest element. Demonstrate the method in a program. Write the JAVA CODE on the paper that is provided. (Put your name on every piece of paper) Use the following array to test the method. Int [] numbers = {2,12,1999,99,100,4,7,300} PROGRAMMING LANGUAGE- JAVA. Please answer the question ASAP. Thanks in advance!