Java Array display arrays

Introduction

To print an array, print each element in the array using a loop like the following:


public class Main {
  public static void main(String[] args) {
    int[] array = new int[5];

    for (int i = 0; i < array.length; i++) { 
      array[i] = (int)(Math.random() * 100); 
    } //from w w  w  .j  a  v  a2  s. c om
    
    for (int i = 0; i < array.length; i++) { 
      System.out.print(array[i] + " "); 
    } 

  }
}



PreviousNext

Related