Kevin321888999

Java Array

Jul 18th, 2022
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. //This program prints an array of numbers from 1-5.
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.     int[] array = new int[5]; //This establishes the total length of the array.
  6.        array= new int[]{1, 2, 3, 4, 5, 6};//Declares the array as a int. And this assigns different values to each array cell.
  7.     for(int i=0;i<=5;i++){
  8.         System.out.println(array[i]);// increments i by one and prints the array above.
  9.     }
  10.         System.out.println("This is the array length: " + array.length);// prints the message and the array length.
  11.  
  12.  
  13.  
  14.  
  15. }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment