Skip to content

Instantly share code, notes, and snippets.

@liuiv15
Created November 26, 2015 14:34
Show Gist options
  • Save liuiv15/95e94556b0162be1bae4 to your computer and use it in GitHub Desktop.
Save liuiv15/95e94556b0162be1bae4 to your computer and use it in GitHub Desktop.
package lesson_1;
import java.util.Arrays;
import java.util.Random;
public class Test_1 {
public static void main(String[] args) {
int data1[] = { 1, 10, 5, 7, 6 };
int data2[] = null;
int data3[] = {};
int data4[] = { 0, 0, 15, 25, 16, 236, 356, 23, 23 };
int data5[] = { -3, 25, 2, -6952 };
printArray(data1);
printArray(data2);
printArray(data3);
printArray(data4);
printArray(data5);
}
static void printArray(int data[]) {
System.out.print("[");
if (data == null || data.length == 0) {
System.out.println("Incorrect array]");
return;
} else {
int i = 0;
while (i <= data.length - 1) {
System.out.print(data[i++]);
if (i == data.length) {
continue;
}
System.out.print(" ,");
}
System.out.println("]");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment