zoukankan      html  css  js  c++  java
  • JAVA使用下面的方法头编写方法,从一个整数的数组列表中去掉重复的元素

    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] +" ");
    }
    }
    }
    }

    输出结果就这:

  • 相关阅读:
    选择排序
    插入排序
    冒泡排序
    linux 常用命令全集
    Boost简介
    postgresql命令行
    Ncurses 命令行图形库
    rsync ssh文件同步
    BusyBox参考
    screen命令
  • 原文地址:https://www.cnblogs.com/RootVount/p/14104765.html
Copyright © 2011-2022 走看看