zoukankan      html  css  js  c++  java
  • 课堂水王2

    设计思路

     对数组进行排序,依次确定数组成员的出现次数,当不相符时,输出成员及其次数

    实验代码

    package yy;
    import java.util.*;
    public class test {
    	public static void main(String[] args) {
    		int array[]={5, 10, 10, 5, 2, 5, 3, 5, 10, 5, 2, 5, 5, 10, 1, 5, 1};
    		Arrays.sort(array);// 给数组排序
    		int count=0;
    		int temp=array[0];
    		for(int i=0;i<array.length;i++)
    		{
    		   if(temp !=array[i]){
    		   System.out.println(temp+"水王:"+count+"次");
    		   temp = array[i];
    		   count=1;
    		}
    		else
    		{
    		 count++;
    		}
    		if(i==array.length-1)
    		{
    		    System.out.println(temp+"水王:"+count+"次");
    		}
    		}
    		
    	}
    
    	
    }
    

    实验截图

    实验总结

      输出一个成员,记得数组次数开始要重新为1;

  • 相关阅读:
    互斥量
    读写锁
    死锁
    pthread
    线程
    守护进程
    信号捕捉
    信号集
    信号
    mmap
  • 原文地址:https://www.cnblogs.com/gdp176119/p/5533831.html
Copyright © 2011-2022 走看看