Java while获取最大值_如何使用do-while循环获得五个数字的总和,平均值,最小值和最大值-java(how to get the sum, average, minimum and ma...

I'm trying to get the sum, average, minimum and maximum of five numbers but somehow I get this output. I'm trying to re-code it all over again but it is still the same. Can you help me check this guys... Here's my code:

import java.util.*;

public class Kleine {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

double average;

int count = 0, sum = 0, num, min = 0, max = 0;

System.out.println("Please enter the number of numbers you wish to evaluate:");

do {

num = scan.nextInt();

sum += num;

count++;

} while (count < 5);

average = sum / 5;

{

if (num > max) {

max = num;

}

if (num < min) {

min = num;

}

}

System.out.println("Your average is: " + average);

System.out.println("The sum is: " + sum);

System.out.println("Your maximum number is: " + max);

System.out.println("Your minimum number is: " + min);

}

}

Here's the output:

Please enter the number of numbers you wish to evaluate:

1

10

5

-3

6

Your average is3.0

The sum is:19

Your maximum number is 6

Your minimum number is 0

BUILD SUCCESSFUL (total time: 19 seconds)

The minimum and maximum numbers goes somewhere... a little advice please...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值