题解 | #记负均正#

记负均正

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

相关推荐

06-12 17:46
门头沟学院 Java
运营你豪哥:来说重点: ​1.项目前置,时间倒序。​​ 2.​项目描述强化结果与量化效果(STAR原则里的R)。​​ ​3.个人技能精炼,明确掌握程度,突出核心。​​ ​4.增加强有力开头的个人总结部分。​​ 5.​优化教育背景(成绩排名)、合并奖项与活动。​​
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
2
分享

创作者周榜

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