Solution:
Thanks for your compliment mate. We are trying to build a strong community with a lot of nice people like you. Let me come to the point. Java is a strongly pass-by-value programming language.
To understand this please check the code below carefully.
import java.util.Scanner;
public class MyMethod {
public int maximum(int [] array) {
int maximum = 0;
for(int n=0; n<array.length; n++ ) {
if(array[n]>maximum) {
maximum = array[x];
}
}
return maximum;
}
public int minimum(int [] array) {
int minimum = array[0];
for(int n = 0; n<array.length; n++ ) {
if(array[n]<minimum) {
minimum = array[n];
}
}
return minimum;
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of the array:");
int size = sc.nextInt();
int[] myArray = new int[size];
System.out.println("Enter the elements of the array :");
for(int n=0; n<size; n++) {
myArray[i] = sc.nextInt();
}
MyMethod x = new MyMethod();
System.out.println("Maximum value in the array is::"+x.maximum(myArray));
System.out.println("Minimum value in the array is::"+x.minimum(myArray));
}
}
After compiling the program if you hit the run button this program will produce something like this:
Enter the size of the array that is to be created:
5
Enter the elements of the array:
45
12
48
53
55
Maximum value in the array is :55
Minimum value in the array is :12
As you can see I prompt the array size and it values and passes the array to my method MyMethod() and it’s returning the value of my arrays with the maximum and minimum value of the array.