java - Finding Duplicates in Arrays -



java - Finding Duplicates in Arrays -

hey i've been messing around in java , created programme go through array , find duplicates in array , working great! there 1 little problem if run programme , there more 2 duplicates of 1 value output 2 duplicates found same value - explain better

output

duplicates in array: 1 duplicates in array: 8 duplicates in array: 8

i've been stuck on time know little error if help me out awesome, code below, thanks

import java.util.arrays; public class duplicates { public static void main (string[] args) { int[] values = { 8, 5, 9, 8, 6, 13, 33, 1, 98, 12, 8, 1 }; arrays.sort(values); for(int = 1; < values.length; i++) { if(values[i] == values[i - 1]) { system.out.println("duplicates in array: " + values[i]); } } } }

if understand question, add together while loop progress past duplicates after study one. like,

public static void main(string[] args) { int[] values = { 8, 5, 9, 8, 6, 13, 33, 1, 98, 12, 8, 1 }; arrays.sort(values); (int = 1; < values.length; i++) { if (values[i] == values[i - 1]) { system.out.println("duplicates in array: " + values[i]); while (values[i] == values[i - 1]) { // <-- add together i++; } } } }

output is

duplicates in array: 1 duplicates in array: 8

java eclipse

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

java - Parsing XML, skip certain tags -

c# - ASP.NET MVC Sequence contains no matching element -