Java 实例 - 查找数组中的重复元素

Java 教程 · 2019-02-10 12:11:43

以下实例演示了如何在 java 中找到重复的元素:

Main.java 文件

public class MainClass { public static void main(String[] args) { int[] my_array = {1, 2, 5, 5, 6, 6, 7, 2, 9, 2}; findDupicateInArray(my_array); } public static void findDupicateInArray(int[] a) { int count=0; for(int j=0;j<a.length;j++) { for(int k =j+1;k<a.length;k++) { if(a[j]==a[k]) { count++; } } if(count==1) System.out.println( "重复元素 : " + a[j] ); count = 0; } } }

以上代码运行输出结果为:

重复元素 : 5
重复元素 : 6
重复元素 : 2

点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

Discrete Mathematics and Its Applications

Discrete Mathematics and Its Applications

Kenneth H Rosen / McGraw-Hill Science/Engineering/Math / 2003-04-22 / USD 132.81

Discrete Mathematics and its Applications is a focused introduction to the primary themes in a discrete mathematics course, as introduced through extensive applications, expansive discussion, and deta......一起来看看 《Discrete Mathematics and Its Applications》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具