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
About Face 2.0
Alan Cooper、Robert M. Reimann / Wiley / March 17, 2003 / USD 35.00
First published seven years ago-just before the World Wide Web exploded into dominance in the software world-About Face rapidly became a bestseller. While the ideas and principles in the original book......一起来看看 《About Face 2.0》 这本书的介绍吧!