Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class creatingArrays {
- public static void main(String[] args) throws Exception {
- String[] array1;
- array1 = new String[4];
- array1[0] ="Ginger Sling";
- array1[1] ="Creme Tangerine";
- array1[2] ="Savoy Truffle";
- array1[3] ="Pineapple Tart";
- System.out.println(array1[2] +" is in index 2");
- // OR
- Double[] array2 = new Double[6];
- array2[0] = 3.2;
- array2[1] = 8.1;
- array2[2] = 6.8;
- array2[3] = 7.2;
- array2[4] = 1.8;
- array2[5] = 6.3;
- System.out.println(array2[3]+ " is in index 3");
- //OR
- String[] array3 = {"Ginger Sling", "Creme Tangerine", "Savoy Truffle", "Pineapple Tart"};
- System.out.println(array3[2]+ " is in index 2");
- // OR
- int[] array4 = {9, 15, 4, 8, 9};
- System.out.println(array4[0]+ " is in index 0");
- System.out.println(array4[6] + "does not exist"); // runtime error
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement