题解 | #记负均正#

记负均正

http://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8

import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
		
		Scanner sr=new Scanner(System.in);
		while(sr.hasNext())
		{
			int count1=0,count2=0;
			double sum=0.0;
			int n=sr.nextInt();
			int[] ar=new int[n];
			for (int i=0;i<n ;i++ )
			{
				ar[i]=sr.nextInt();
			}
			for (int i=0;i<ar.length ;i++ )
			{
				if (ar[i]<0)
					count1++;
				if (ar[i]>0)
				{
					sum+=ar[i];
					count2++;
				}
			}
			System.out.print(count1+" "+String.format("%.1f",sum/count2)+"\n");
		}
		sr.close();
	}
}
全部评论
这个答案过不了用例吧
点赞 回复 分享
发布于 2023-03-14 17:23 浙江
没判断输入的n个整数都为0时,平均值为?
点赞 回复 分享
发布于 2022-04-30 17:26

相关推荐

点赞 评论 收藏
分享
搞机墨镜猫:科研和竞赛全写成项目经历,另外你项目涉及到的技术栈太杂了,应该对不同岗位强调写不同的技术栈,寒假应该不太好找短期,长期明年3,4月好找很多
点赞 评论 收藏
分享
Morpheus_:同 好奇什么题() 不过我一面确实是不想要直说了 xs
腾讯求职进展汇总
点赞 评论 收藏
分享
评论
1
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务