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