Và đây là đoạn code của mình :
package Task1;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author dangpham
*/
public class Task1_1 {
private ArrayList<Integer> array = new ArrayList<>();
private int length;
//From line 10 to 24 , codes of input and output
public void input() {
Scanner scanner = new Scanner(System.in);
if (array.isEmpty()) {
for (int i = 0; i < length; i++) {
int a = scanner.nextInt();
array.add(a);
}
}
}
public void output() {
for (int i = 0 ; i < array.size() ; i++) {
System.out.println(array.get(i) + " ");
}
}
// from line 27 to 42 , codes of check and print prime numbers
public boolean isPrimeNumber(int a) {
for (int i = 2 ; i <= Math.sqrt(a) ; i++) {
if (a % i == 0) {
return false;
}
}
return true;
}
public void PrintPrimeNumber() {
for (int i = 0 ; i < array.size() ; i++) {
if (isPrimeNumber(array.get(i))) {
System.out.println(array.get(i) + " ");
}
}
}
//from line 45 to 56 , codes of Insertion Sort
void InsertionSort() {
int n = array.size();
for (int i = 1; i < n; ++i) {
int key = array.get(i);
int j = i - 1;
while (j >= 0 && array.get(j) > key) {
array.set(j + 1 , array.get(j));
j = j - 1;
}
array.set(j + 1 , key);
}
}
//from line 62 to 86 , codes of Quick Sort
int partition(ArrayList<Integer> arr, int low, int high) {
int pivot = arr.get(high);
int i = (low - 1);
for (int j = low; j < high; j++) {
if (arr.get(j) < pivot) {
i++;
int temp = arr.get(i);
arr.set(i, arr.get(j));
arr.set(j , temp);
}
}
int temp = arr.get(i+1);
arr.set(i+1 , arr.get(high));
arr.set(high, temp);
return i + 1;
}
void Quicksort(ArrayList<Integer> arr, int low, int high) {
if (low < high) {
int pi = partition(arr, low, high);
Quicksort(arr, low, pi - 1);
Quicksort(arr, pi + 1, high);
}
}
// from 89 to 104 , codes of setter and getter method
public ArrayList<Integer> getArray() {
return array;
}
public void setArray(ArrayList<Integer> array) {
this.array = array;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
}