Write a Java program to find the duplicate values of an array of integer values


Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. import java.util.Arrays;
  2. public class Javaexcercise {
  3. public static void main(String[] args)
  4. {
  5. int[] my_array = {1, 2, 3, 4, 5, 6, 7, 2, 3, 4};
  6.  
  7. for (int i = 0; i < my_array.length-1; i++)
  8. {
  9. for (int j = i+1; j < my_array.length; j++)
  10. {
  11. if ((my_array[i] == my_array[j]) && (i != j))
  12. {
  13. System.out.println("Duplicate array element : "+my_array[j]);
  14. }
  15. }
  16. }
  17. }
  18. }

Result

java techstudy.org

     





Related Topics




Popular Posts