Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.java.main;
- public class Sam
- {
- public static void main(String args[])
- {
- int[] ages; // declaration
- ages = new int[100]; // creation
- ages[0] = 16;
- System.out.println(ages[0] + "\n");
- ages[1] = 18;
- ages[0]++;
- System.out.println(ages[0] + "\n");
- for(int x = 0; x < 100; x++)
- {
- System.out.println(ages[x] + "\n");
- }
- int[] ages1 = new int[5];
- int[] ages2 = {16, 18, 15, 16, 17}; // initializer list
- int[] ages3 = new int[]{16, 18, 15, 16, 17};
- String[] names = new String[100];
- names[0] = "Sammy";
- names[1] = "Brendan";
- for(int i = 0; i < 100; i++)
- {
- System.out.println("Name is: " + names[i] + " | Age is: " + ages[i] + "\n");
- }
- }
- }
- /* Ways to Declare an Array
- int[] myIntArray = new int[3];
- int[] myIntArray = {1,2,3};
- int[] myIntArray = new int[]{1,2,3};
- */
Advertisement
Add Comment
Please, Sign In to add comment