+ 1

I can't count the number of duplicate in array

//Write a program that will count total number of duplicate elements in array import java.util.Scanner; public class Yui{ public static void main(String [] args){ Scanner sc = new Scanner(System.in); int [] elements = new int [3]; int dup = 0; for(int ctr = 0; ctr <elements.length;ctr++){ System.out.print("Enter number of element: " ); elements[ctr] = sc.nextInt(); System.out.println("element " + " : " + elements[ctr]); if(elements[ctr] == elements[ctr]){ dup += 1; } } System.out.println("Total duplicate elements found in the array is: " + dup); } } ,

22nd Sep 2018, 3:46 PM
Reginald Tobias
Reginald Tobias - avatar
0 Respuestas