Implement a Java program to remove duplicates from an array.

Here’s a Java program to remove duplicates from an array:

import java.util.Arrays;
import java.util.Scanner;

public class RemoveDuplicates {
    public static void main(String[] args) {
        int[] arr = new int[5];
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter 5 numbers: ");
        for (int i = 0; i < 5; i++) {
            arr[i] = scanner.nextInt();
        }
        int[] newArr = removeDuplicates(arr);
        System.out.println("Array without duplicates: " + Arrays.toString(newArr));
    }

    public static int[] removeDuplicates(int[] arr) {
        Arrays.sort(arr);
        int[] newArr = new int[arr.length];
        int j = 0;
        for (int i = 0; i < arr.length - 1; i++) {
            if (arr[i] != arr[i + 1]) {
                newArr[j++] = arr[i];
            }
        }
        newArr[j++] = arr[arr.length - 1];
        int[] finalArr = new int[j];
        for (int i = 0; i < j; i++) {
            finalArr[i] = newArr[i];
        }
        return finalArr;
    }
}

In this program, we first create an integer array of size 5 and take user input for its elements using a for loop. We then call the `removeDuplicates()` method to remove duplicates from the array.

The `removeDuplicates()` method takes an integer array as a parameter and returns a new array with duplicates removed. We first sort the array using the `Arrays.sort()` method. We then create a new integer array `newArr` with the same length as the input array. We use a for loop to iterate over each element of the input array. For each element, we check if it is equal to the next element. If it is not, then we add it to the `newArr` array. We keep track of the index of the next available position in the `newArr` array using a variable `j`. We then create a new integer array `finalArr` with length `j` and copy the elements of `newArr` up to index `j` into it. We then return `finalArr`, which is the array without duplicates.

At the end of the program, we print out the array without duplicates using the `Arrays.toString()` method.