I wanted to use the varags method to take the input of various integers and find out the maximum & minimum among them.
public class MINMAX {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
Maximum(a,b,c);
Minimum(a,b,c);
}
static void Maximum(int ...v) {
int max = Math.max(a,Math.max(b,c));
System.out.println("The Largest no. is: "+max);
}
static void Minimum(int ...v) {
int min = Math.min(a,Math.min(b,c));
System.out.println("The Smallest no. is: "+min);
}
}
Here, I'm taking input of a,b,c from the user to find out the max & min. but want to know how can i target the specific elements in Varargs Method.