最大值计算过程(Find the Largest Number)
来源:互联网 发布:知乎手机最好的变声器 编辑:程序博客网 时间:2024/06/05 08:14
算是超简单的问题了吧,Excel中用一个max()函数就能搞定的问题,我要写这么长代码才实现。
不过,写代码有一种自由的感觉。在找到最大值的同时,可以告诉你最大值在哪里。(相信Excel也有相应功能)
补记:
Excel中查找一列数据中的最大值所在行,公式为:INDEX(A:A,MATCH(MAX(B:B),B:B))
代码如下:
//JHTP Exercise 4.21: Find the Largest Number//by pandenghuang@163.com/* (Find the Largest Number) The process of finding the largest value is used frequently in computer*applications. For example, a program that determines the winner of a sales contest would input*the number of units sold by each salesperson. The salesperson who sells the most units wins the contest.*Write a pseudocode program, then a Java application that inputs a series of 10 integers and determines*and prints the largest integer. Your program should use at least the following three variables:*a) counter: A counter to count to 10 (i.e., to keep track of how many numbers have been*input and to determine when all 10 numbers have been processed).*b) number: The integer most recently input by the user.*c) largest: The largest number found so far.*/import java.util.Scanner;public class Test {public static void main(String[] args) {int counter=1;int largest=0;Scanner scanner=new Scanner(System.in);int number=0;int salesNo=1;int maxSalesNo=1;while (counter<=10){System.out.printf("请输入销售员No.%d的销售额:",salesNo);number=scanner.nextInt();if(number>=largest){largest=number;maxSalesNo=salesNo;}++counter;++salesNo;}System.out.printf("恭喜销售员No.%d创造了最高销售额:%d RMB",maxSalesNo,largest);}}
运行结果:
请输入销售员No.1的销售额:1
请输入销售员No.2的销售额:2
请输入销售员No.3的销售额:3
请输入销售员No.4的销售额:9
请输入销售员No.5的销售额:8
请输入销售员No.6的销售额:7
请输入销售员No.7的销售额:6
请输入销售员No.8的销售额:5
请输入销售员No.9的销售额:4
请输入销售员No.10的销售额:2
恭喜销售员No.4创造了最高销售额:9 RMB
0 0
- 最大值计算过程(Find the Largest Number)
- The K-th largest number(小根堆)
- Array(11) -- Largest Rectangle in Histogram, Maximal Rectangle, Find the Duplicate Number
- find kth largest number in an array
- LeetCode-515. Find Largest Value in Each Tree Row (JAVA)(二叉树每行的最大值)
- Find Largest Value in Each Tree Row(找出一棵树每一行的最大值)
- LeetCode(287)Find the Duplicate Number
- Find the Duplicate Number(Leetcode 287)
- 287. Find the Duplicate Number(链表判环)
- Find the Difference(类似 Single Number)
- Leetcode287 - Find the Duplicate Number(二分)
- Find the Prime Number
- Find the Duplicate Number
- Find the Duplicate Number
- Find the Duplicate Number
- Find the Duplicate Number
- Find the Duplicate Number
- Find the Duplicate Number
- 浏览器开发者选项运行以下代码
- JavaScript HTML DOM
- Java Security:Java加密框架(JCA)简要说明
- PopupWindow无法全屏显示
- python获取页面元素的内容及长度
- 最大值计算过程(Find the Largest Number)
- Maven 与 IntelliJ IDEA 的完美结合
- 改进型clock算法--页面置换算法
- Android Studio使用技巧
- 麒麟开源堡垒机 应急预案
- IntentService分析
- mod微信,qq等分享
- linux 下 配置 jdk
- 阿里云服务器windows远程桌面控制