一道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

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/28 21:06:37
一道Java的题目求编程ProblemDescription:Writeaprogramthatreadsintegers,findsthelargestofthem,andcountsitsoccu

一道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
一道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

一道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

首先你读懂题没有,我帮你翻译一下:


问题描述: 

编写一个程序,读取整数,找出其中最大的,并计算其出现次数.假设输入与数字0结束.假设你进入3 5 2 5 5 5 0;程序发现,最大的为5,出现次数为4. (提示:建立两个变量,最大值和计数值,最大存储当前的最大数量,并计算其出现次数,分配一个最大值和1来计算比较每个后续数,最大如果人数大于最大. ,将其分配到最大,并重置计数为1,如果数等于最大,由1递增计数.) 


下面是该程序的运行示例: 

 

示例1: 

输入数字:3 5 2 5 5 5 0 

最大数量为5 

出现次数为4 

 

示例2: 

输入数字:3 6 5 4 2 4 5 4 5 5 0  

最大数是6 

出现次数为1


简单的说,问题就是随便输入一串数字,找出最大值,并且计算其出现次数!

问题搞清楚了,就来编程吧,经测试,我的代码可以正确运行:


package test01;


import java.util.Scanner;


public class TestSystemIn {

public static void main(String[] args) {

System.out.println("请输入内容,不同内容以逗号隔开,请以0结尾,以回车结束");

Scanner scanner = new Scanner(System.in);

String str = scanner.next();

String a[] = str.split(",");

int temp = 0;

if (0 != (Integer.parseInt(a[a.length - 1]))) {

System.out.println("请以0结尾");

return;

}

for (int i = 0; i < a.length; i++) {

if (Integer.parseInt(a[i]) > temp) {

temp = Integer.parseInt(a[i]);

}

}

System.out.println("最大的为:" + temp);

int max = temp;

int times = 0;

for (int i = 0; i < a.length; i++) {

if (Integer.parseInt(a[i]) == max) {

times++;

}

}

System.out.println("出现的次数为:" + times);

}

}


一道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 数学编程高手请进一道求公式的题目求这个题目的公式, 求java编程题:计算1到100累加的和java编程求1到100相加之和 求Java编程,计算并输出1+2!+3!+…+10!的值提问错了,是图片的那个题目 求会英文的java大神帮忙解决一道编程题Write a program that will ask a user for the total hours worked.If the hours worked JAVA编程,输入一个四位数,求四位数的每位数字之和!是JAVA,不是C语言! java 5+55+555+5555+...求和编程题:求5+55+555……的前十项的和用java编程,谢拉... 一道英文的Java编程题目Create a program that uses variables and methods to read some informationabout a bank customer and handle his/her account.The information thatshould be read is namn,address,phone number and account number.Theinformation 求java编程题目解:编程求解鸡兔问题,鸡兔共有49只,但有100只足,计算鸡兔各多少只? java 编程,求1000以内能被17整除数的和 1、编写一个长方体类,求长方体的体积和表面积(JAVA编程) 求问java语言基础的一道小编程 C也可以~用java编写程序输出下列结果 :C也可以 主要要一个思路 11 21 2 31 2 3 41 2 3 4 51 2 3 4 5 6求全部编程 java编程:用java编程计算1到10的整数和?求救! java编程打印“九九乘法口诀表”的程序用java编程实现“九九乘法口诀表”. 一道JAVA题目,5个数,从小到大排列, 对有道编程题的题目要求有些不理解~For the solution,we request that you use either Java,C++,Ruby or C#.You may not use any externallibraries to solve this problem,but you may use external libraries or tools for building or testing purpo 杭电ACM比赛的一道题目,A.Shooshuns and SequenceTime Limit :4000/2000ms (Java/Other) Memory Limit :524288/262144K (Java/Other)Total Submission(s) :130 Accepted Submission(s) :34Problem DescriptionOne day shooshuns found a sequence of n integer 这是一道acm题目,不知道为什么我的答案总是不对Problem J Time Limit :2000/1000ms (Java/Other) Memory Limit :65536/32768K (Java/Other)Total Submission(s) :185 Accepted Submission(s) :42Font:Times New Roman | Verdana | Georgia Font Siz