Prints an array to screen. - Java java.lang

Java examples for java.lang:int Array

Description

Prints an array to screen.

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        double[] v = new double[] { 34.45, 35.45, 36.67, 37.78, 37.0000,
                37.1234, 67.2344, 68.34534, 69.87700 };
        print(v);/*from w  ww.j  a va  2s . c  om*/
    }

    /**
     * Prints an array to screen.
     */
    public static void print(double[] v) {
        for (int k = 0; k < v.length; k++) {
            System.out.println("array [" + k + "] = " + v[k]);
        }
    }

    /**
     * Prints an array to screen.
     */
    public static void print(double[][] v) {
        for (int k = 0; k < v.length; k++) {
            for (int l = 0; l < v[k].length; l++) {
                System.out.println("array [" + k + "][" + l + "] = "
                        + v[k][l]);
            }
        }
    }

    /**
     * Prints an array to screen.
     */
    public static void print(int[] v) {
        for (int k = 0; k < v.length; k++) {
            System.out.println("array [" + k + "] = " + v[k]);
        }
    }

    /**
     * Prints an array to screen.
     */
    public static void print(int[][] v) {
        for (int k = 0; k < v.length; k++) {
            for (int l = 0; l < v[k].length; l++) {
                System.out.println("array [" + k + "][" + l + "] = "
                        + v[k][l]);
            }
        }
    }
}

Related Tutorials