Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Ex2 {
- // Write a Java program to find the duplicate values of an array of integer
- // values
- public static void main(String[] args) {
- int[] arr = { 1, 7, 13, 9, 1, 5, 8, 7, 5, 9, 21 };
- // output: 1 7 13 9 5 8 21
- // print source array
- System.out.print("Source array : ");
- for (int i = 0; i < arr.length; i += 1) {
- System.out.print(arr[i] + " ");
- }
- System.out.println();
- // print without duplicates
- System.out.print("array without duplicates: ");
- for (int i = 0; i < arr.length; i += 1) {
- boolean print = true;
- for (int j = 0; j < i && print; j += 1) {
- if (arr[i] == arr[j]) {
- print = false;
- }
- }
- if (print) {
- System.out.print(arr[i] + " ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement