请教两句话的区别

无法支持的类型 2016-08-26 03:13:55
  public void run() {     
Scanner fin = new Scanner(System.in);
int N = fin.nextInt();
int[] count = new int[10001];
for (int i = 0; i < N; ++i) {
/* ++count[fin.nextInt()]; */
count[i]=fin.nextInt();
}
int maxCount = -1;
int result = 0;
for (int i = 1; i <= 10000; ++i) {
if (count[i] > maxCount) {
maxCount = count[i];
result = i;
}
}
System.out.println(result);
}

/* ++count[fin.nextInt()]; */
count[i]=fin.nextInt();
这两句话有什么区别?
...全文
305 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
codingjav 2016-08-27
  • 打赏
  • 举报
回复
楼上解释的很清楚撒
soton_dolphin 2016-08-26
  • 打赏
  • 举报
回复
因为int 数组初始化元素都是0 啊
  • 打赏
  • 举报
回复
现在我百思不得其解
引用
 public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);  
      int n = sc.nextInt();    
      int[] arr = new int[10001];     
      for(int i =0;i<n;i++){
    	  int temp=sc.nextInt();
//    	  System.out.println("++++"+temp+"++++");
    	  arr[temp]= arr[temp]+1;
 //   	 System.out.println("***"+i+"***"+arr[temp]+"***");
      }
      int MaxCount=-1;
      int result=0;
      for(int i=0;i<n;i++){
        if(arr[i]>MaxCount){
        	MaxCount=arr[i];
        	System.out.println("++++"+i+"++"+arr[i]+"++"+MaxCount+"++++");
        	result=i;
        	
      }else{
    	  System.out.println("---"+i+"--"+arr[i]+"--"+MaxCount+"--");
      }
       
      } System.out.println(result);
}
 for(int i=0;i<n;i++){
        if(arr[i]>MaxCount){
        	MaxCount=arr[i];
        	System.out.println("++++"+i+"++"+arr[i]+"++"+MaxCount+"++++");
        	result=i;
        	
      }else{
    	  System.out.println("---"+i+"--"+arr[i]+"--"+MaxCount+"--");
      }
       
      }
++++0++0++0++++ ++++1++4++4++++ ---2--4--4-- ---3--1--4-- ---4--0--4-- ---5--0--4-- ---6--0--4-- ---7--0--4-- ---8--0--4-- 这段代码怎么输出是这个样子 arr[4]为什么是0;
soton_dolphin 2016-08-26
  • 打赏
  • 举报
回复
假设 fin.nextInt() = 3; ++count[fin.nextInt()] 相当于 count[3] = count[3] + 1 count[i] = fin.nextInt() 相当于 count[i] = 3

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧