-
-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathMain.java
More file actions
38 lines (35 loc) · 920 Bytes
/
Main.java
File metadata and controls
38 lines (35 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class Main {
public static void main(String[] args) {
Array arr = new Array();
arr.displayAllElements();
}
}
class Array {
private int[] array;
private int size;
private int length;
public Array() {
this.size = 13;
this.length = 13;
this.array = new int[this.size];
for (int i = 0; i < this.size; i++) {
this.array[i] = i;
}
}
public Array(int size) {
this.size = size;
this.length = 0;
this.array = new int[this.size];
}
public void displayAllElements() {
if (length == 0) {
System.out.println("No elements in array.");
} else {
System.out.print("Elements of array are: ");
for (int i = 0; i < length; i++) {
System.out.print(array[i] + " ");
}
System.out.println();
}
}
}