zoukankan      html  css  js  c++  java
  • java输出数组中出现的次数最多的那个及次数

    总结:理解每一个定义的变量

    package com.aini;
    
    //一组数据,要求统计出最大值出现了多少次
    public class Xd {
    	public static void main(String[] args) {
    		int a[] = new int[10];// a是对象名
    		String b[] = { "123", "32", "123", "5", "123","5", "123","5", "123", "123" };//
    		for (int i = 0; i < b.length; i++) {
    			for (int j = 0; j < b.length; j++) {
    				if (b[i].equals(b[j]))
    					a[i]++;// 
    			}
    
    		}
    		int couut= 0;//a[b.length - 1];// 
    		int countindex = 0;
    		// int count=a[0];
    		for (int i = 0; i < b.length - 1; i++) {
    
    			if (count <= a[i]) {
    				count = a[i];
    				countindex = i;// 输出最大值的索引
    
    			}
    
    		}
    		System.out.println(b[countindex] + "出现了" + count + "次");
    
    	}
    
    }
    

      

  • 相关阅读:
    对坐标点的离散化
    线段树-离散化处理点
    树状数组
    线段树
    dfs
    vector
    go 参数传递的是值还是引用 (转)
    go 数组指针 指针数组
    go 协程
    go 接口实现
  • 原文地址:https://www.cnblogs.com/langlove/p/3403573.html
Copyright © 2011-2022 走看看