首页 > 编程语言 > 详细

JAVA使用下面的方法头编写方法,从一个整数的数组列表中去掉重复的元素

时间:2020-12-08 18:23:29      阅读:135      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 

import java.util.Scanner;
public class GAGA{
public static void main(String args[]){
Scanner input = new Scanner(System.in);
//提示输入
System.out.print("Enter ten numbers: ");
int[] a = new int[10];
for(int i = 0; i < 10; i++)
{
a[i] = input.nextInt();
}
//筛选
System.out.print("The distinct numbers are: ");
int[] b = {1,1,1,1,1,1,1,1,1,1};
for(int i = 0; i < 10; i++)
{
for(int j = 9; j > i; j--)
{
if(a[i] == a[j])
{
b[j] = -1;
}
}
}
//输出
for(int i = 0; i < 10; i++)
{
if(b[i] == 1)
{
System.out.print(a[i] +" ");
}
}
}
}

输出结果就这:

技术分享图片

JAVA使用下面的方法头编写方法,从一个整数的数组列表中去掉重复的元素

原文:https://www.cnblogs.com/RootVount/p/14104765.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!