一道Java的题目 求编程
题目
一道Java的题目 求编程
Problem Description:
Write a program that reads integers,findsthe largest of them,and counts its occurrences.Assume that the input endswith number 0.Suppose that you entered 3 5 2 5 5 5 0; the program finds thatthe largest is 5 and the occurrence count for 5 is 4.(Hint:Maintain twovariables,max and count.max stores the current max number,and count storesits occurrences.Initially,assign the first number to max and 1 to count.Compare each subsequent number with max.If the number is greater than max,assign it to max and reset count to 1.If the number is equal to max,incrementcount by 1.)
Here are sample runs of the program:
Sample 1:
Enternumbers:3 5 2 5 5 5 0
Thelargest number is 5
Theoccurrence count of the largest number is 4
Sample 2:
Enternumbers:3 6 5 4 2 4 5 4 55 0
Thelargest number is 6
Theoccurrence count of the largest number is 1
答案
首先你读懂题没有,我帮你翻译一下:问题描述: 编写一个程序,读取整数,找出其中最大的,并计算其出现次数.假设输入与数字0结束.假设你进入3 5 2 5 5 5 0;程序发现,最大的为5,出现次数为4. (提示:建立两个变量,...
举一反三
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
最新试题
热门考点
- 已知有HCl,H2O,NaOH,Na2CO3,CaCO3,NaCl,CaO,Ca(OH)2,Cu,Fe,Al,明矾.能制取出什么?越多越好.
- 检验Na2SO4溶液中含有Cl-的方法是什么?
- 下列现象与太阳辐射无关的是
- 分析加点词的表达效果
- 请仔细观察给出的两个字,根据字的偏旁猜成语.1.奏——春( ) 2.沙——砂( ) 3.咕——吟( )
- 人与人之间关系 的名人名言
- 加热某Na2HCO3和Na2CO3·xH2O的混合物40.0g,至不再产生气体为止,得残留固体21.2g,把加热所产生的气体通入含8.55gBa(OH)2的溶液中去,恰好使所生成的沉淀完全消失,则x的
- 爸爸的年龄是冬冬的5倍,5年后,爸爸比冬冬大24岁,5年后,爸爸和冬冬各多少岁?
- 在Excel中,默认情况中,单元格名称使用的是 A.相对引用 B.绝对引用 C.混合应用 D.三维相对引用
- 中国三次历史巨变是什么