Skip to content

Instantly share code, notes, and snippets.

@Yur-ok
Created December 18, 2015 09:11
Show Gist options
  • Save Yur-ok/9f92c313d524a5fbbddb to your computer and use it in GitHub Desktop.
Save Yur-ok/9f92c313d524a5fbbddb to your computer and use it in GitHub Desktop.
package Lesson3.KeyPoint1;
import java.util.Arrays;
/**
* Created by Юрий on 16.12.2015.
*/
public class PrintArray {
public static void main(String[] args) {
int[] arr1 = {1, 10, 5, 7, 6};
int[] arr2 = {0};
int[] arr3 = new int[0];
int[] arr4 = {0, 0, 15, 25, 16};
int[] arr5 = {-3, 25, 2};
printArray(arr1);
printArray(arr2);
printArray(arr3);
printArray(arr4);
printArray(arr5);
}
static void printArray(int[] data) {
System.out.print("[");
if (data != null && data.length > 0) {
int lastI = data.length - 1;
int i = 0;
while (i < lastI) {
System.out.print(data[i++] + ", ");
}
System.out.print(data[data.length - 1]);
}
System.out.println("]");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment