A Java program to demonstrate how to declare and use user-defined methods and arrays.
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

Please subscribe to my channel  https://www.youtube.com/channel/UCOs-lpOoIeJoh6gpJthPoGg

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



Want to support my channel?

GCash Account

Jake Pomperada

09173084360



Paypal

https://paypal.me/jakerpomperada



Patreon

https://www.patreon.com/jakerpomperada



Thank you very much for your support.



Program Listing



Max_Min.java


public class Max_Min {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		 double[] myList = {1.2, 9.3, 1.6, 2.5}; // Declare the array; assign values into array

		    // Call the dispArray user-defined method to display the array contents to screen.
		    dispArray(myList);
	   	    
		    Sum_Average(myList);
		    Max_Value(myList);
            Min_Value(myList);
	 
		  }

		  public static void dispArray(double[] myList) {

		    // Print all the array elements
		    System.out.println("These are the elements in the array:");
		    System.out.print("|");
		    for (int i = 0; i < myList.length; i++) {
		      System.out.print(myList[i] + "|");
		    }
		    System.out.println();

		  }
  
		
		  
		  private static void Sum_Average(double[] myList) {
			  // Summing and averaging all elements
			    double sum = 0;

			    for (int i = 0; i < myList.length; i++) {
			      sum += myList[i];
			    }
			    System.out.println();
			    System.out.println("Total is " + sum);
			    System.out.println("Average is " + (sum / myList.length));

		    }

		  
		  private static void Max_Value(double[] myList) {
			  // Finding the largest element
			    double max = myList[0];
			    for (int i = 1; i < myList.length; i++) {
			      if (myList[i] > max) max = myList[i];
			    }

			    System.out.println("Max is " + max);
		    }
		  
		  private static void Min_Value(double[] myList) {
			   // Finding the smallest element
			    double min = myList[0];
			    for (int i = 1; i < myList.length; i++) {
			      if (myList[i] < min) min = myList[i];
			    }

			    System.out.println("Min is " + min);

		  }
	} // End of Code


Leave a Reply

Your email address will not be published.