Advertisement
sergAccount

Untitled

Jul 3rd, 2021
1,257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.mycompany.ex16;
  7.  
  8. /**
  9.  *
  10.  * @author student
  11.  */
  12. public class Main9 {
  13.    
  14.     /*
  15.      // метод зависит от массива элементов
  16.     public static int minOfArray(int[] array){        
  17.         return 0;
  18.     }
  19.     */
  20.     // метод с произвольным количеством параметров (VarArgs)
  21.     public static int min(int ... values){
  22.         //
  23.         System.out.println("values.len=" + values.length);
  24.         for (int i = 0; i < values.length; i++) {
  25.             int value = values[i];
  26.             System.out.println("value=" + value);
  27.         }        
  28.         return 0;
  29.     }
  30.     //
  31.     public static void main(String[] args) {
  32.         //
  33.         System.out.println("2 params");
  34.         min(2, 4);
  35.         System.out.println("3 params");
  36.         min(2, 4, 3);
  37.         System.out.println("4 params");
  38.         min(2, 4, 3, 4);
  39.         //
  40.         int[] arr = {1, 2, 3};
  41.         min(arr);
  42.        
  43.         min();
  44.     }    
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement