“Java Array Periksa Duplikat” Kode Jawaban

Temukan nilai duplikat di array menggunakan java

public class DuplicateArrayElement {
  public static void main(String[] args) {
    int[] numArray = {2, 6, 7, 6, 2, 19, 1, 19};
    for(int i = 0; i < numArray.length; i++){
      for(int j = i + 1; j < numArray.length; j++){
        if(numArray[i] == numArray[j]){
          System.out.println("Duplicate element found " + numArray[j]);
        }
      }
    }    
  }
}
Annoying Angelfish

Java Array Periksa Duplikat

duplicates = false;

for(i = 0; i < zipcodeList.length; i++) {
	for(j = i + 1; k < zipcodeList.length; j++) {
  		if(j != i && zipcodeList[j] == zipcodeList[i]) {
   	  		duplicates = true;
		}
	}
}
Soulless Creature

Java Memeriksa jumlah duplikat dalam array

import java.util.*;
public class DuplicateClass {

    public static void main(String[] args) {
        int[] values = { 7, 2, 6, 1, 4, 7, 4, 5, 4, 7, 7, 3, 1 };
        duplicate(values);
    }

    public static void duplicate(int numbers[]) {
        Arrays.sort(numbers);
        int previous = numbers[0] - 1;
        
        int dupCount = 0;

        for (int i = 0; i < numbers.length; ++i) {
            if (numbers[i] == previous) {
                ++dupCount;
            } else {
                previous = numbers[i];
            }
        }
        System.out.println("There were " + dupCount + " duplicates in the array.");
    }
}
Splendid Starling

java temukan duplikat di array

// Uses a set, which does not allow duplicates 

for (String name : names) 
{
     if (set.add(name) == false) 
     {
        // print name your duplicate element
     }
}
Lively Lizard

Jawaban yang mirip dengan “Java Array Periksa Duplikat”

Pertanyaan yang mirip dengan “Java Array Periksa Duplikat”

Lebih banyak jawaban terkait untuk “Java Array Periksa Duplikat” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya