// exbl3.bal example declare and print variable, vector, matrix // ballerina run exbl3.bal import ballerina/io; public function main (string... args) { io:println("exbl3.bal running"); int n = 3; n = n + 3; io:println("n=",n); float x = 1.0; float y = x+2.0; io:println("x=",x,", y=",y); // This creates an `int` array of length 0. int[] a = []; io:println("lengthof a = ",a.length()); // This assigns an array literal. int[] b = [1, 2, 3, 4, 5, 6, 7, 8]; io:println("b[0]) = ",b[0]); io:println("b[7]) = ",b[7]); io:println("lengthof b = ",b.length()); foreach int i in 0...7 { io:println("b[",i,"]=",b[i]); } // Arrays are unbounded in length. // They can grow up to any length based on the given index. // In this example, the length of the array is 1000. b[999] = 23; io:println("b[999] = ",b[999]); io:println("lengthof b = ",b.length()); //This initializes an array of int arrays. int[][] iarray = [[1, 2, 3, 4], [10, 20, 30, 40], [5, 6, 7,8]]; io:println("lengthof iarray =",iarray.length()); io:println("lengthof iarray[0] = ",iarray[0].length()); // This initializes the outermost array with the implicit default value. iarray = []; int[] d = [9]; iarray[0] = d; io:println("lengthof iarray =",iarray.length()); io:println("lengthof iarray[0] = ",iarray[0].length()); // This prints the first value of the two-dimensional array. io:println("iarray[0][0] = ",iarray[0][0]); // This creates a sealed `int` array of length 5. int[5] e = [1, 2, 3, 4, 5]; io:println("lengthof e = ",e.length()); // This creates a sealed `int` array of length 5 int[5] f = [0, 0, 0, 0, 0]; io:println("lengthof f =",f.length()); // To infer the size of the sealed array from the array literal, // following syntax is used. int[] g = [1, 2, 3, 4]; io:println("lengthof g =",g.length()); io:println("arrays.bal finished"); io:println("exbl3.bal ends"); } // end exbl3.bal