Advertisement
therrontelford

Arrays creating with method

Jan 15th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1.  
  2. public class CreateArrayWithMethod {
  3.  
  4.     public static void main(String[] args) {
  5.         //calling methods to make arrays
  6.         int[] myArray = createArray(12);
  7.         initialize(myArray);
  8.         print(myArray);
  9.  
  10.     }
  11.     public static int[] createArray(int size){
  12.         int[] array = new int[size];
  13.         return array;
  14.     }
  15.     public static int[] initialize(int [] array){
  16.         for (int i=0; i<array.length; i++){
  17.             array[i]= (int)(Math.random()* 100);
  18.         }
  19.         return array;
  20.     }
  21.     public static void print(int [] array){
  22.         for (int e: array)
  23.             System.out.print(e + " ");
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement