Using a programmerdefined function maximum to determine and

Using a programmer-defined function maximum to determine and return the largest of five integers.

Solution

Find the solution below:

===========================================================================

import java.util.Scanner;

public class Maximum {
   Scanner sc = new Scanner(System.in);

   public static void main(String args[]) {
       Maximum m = new Maximum(); //object creation for class
       int array[] = new int[5]; //array declaration with size 5
       array = m.readInput();       //method calling for read input
       int bignumber = m.largestValue(array); // method calling for large element
       System.out.println(bignumber + \" is larger in \" + array.length + \" elements...\"); //printing the larger element
   }

   int[] readInput() { //method for reading input from user
       int array[] = new int[5];
       System.out.println(\"enter the five integers\");
       for (int i = 0; i < array.length; i++) { //elements inserting into array
           array[i] = sc.nextInt();
       }
       return array;
   }

   int largestValue(int[] array) { //method to find largest element among array
       int bignumber = 0;
       for (int i = 0; i < array.length; i++) {
           if (bignumber < array[i]) {
               bignumber = array[i];
           }
       }
       return bignumber; //returning largest value
   }

}

===========================================================================

INPUT:

enter the five integers
8
49
52
6
100

==========================================================================

OUTPUT:


100 is larger in 5 elements...

==========================================================================

 Using a programmer-defined function maximum to determine and return the largest of five integers.SolutionFind the solution below: =============================

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site