Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding java code #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions 002_ARRAY/001_Initializing_Array_ADT/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.util.Scanner;

class Array {
private int[] array;
private int size;
private int length;

public Array() {
this.size = 13;
this.length = 0;
this.array = new int[this.size];
}

public Array(int size) {
this.size = size;
this.length = 0;
this.array = new int[this.size];
}
}

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

Array arr1, arr2;

System.out.print("Enter size: ");
int size = scanner.nextInt();

arr1 = new Array(size);
arr2 = new Array();

scanner.close();
}
}
38 changes: 38 additions & 0 deletions 002_ARRAY/002_Displaying_an_Array/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,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();
}
}
}
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.