Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

public class Main {
    public static void main(String[] args) {
        int[] iArr = new int[1];
        int[][] iiArr = new int[1][1];
        int[][][] iiiArr = new int[1][1][1];

        String[] sArr = { "A", "B" };
        String[][] ssArr = { { "A" }, { "B" } };
        String[][][] sssArr = {}; // A 3D empty array of string

        // Print the class name for all arrays
        System.out.println("int[]:" + getClassName(iArr));
        System.out.println("int[][]:" + getClassName(iiArr));
        System.out.println("int[][][]:" + getClassName(iiiArr));
        System.out.println("String[]:" + getClassName(sArr));
        System.out.println("String[][]:" + getClassName(ssArr));
        System.out.println("String[][][]:" + getClassName(sssArr));
    }

    public static String getClassName(Object obj) {
        Class c = obj.getClass();
        String className = c.getName();
        return className;
    }
}