gpt4 book ai didi

java - 计算最小值和最大值并四舍五入到近值

转载 作者:行者123 更新时间:2023-12-01 14:08:10 26 4
gpt4 key购买 nike

我的数学很弱,我需要一些关于最小值和最大值计算的帮助吗?

假设将MinValue 设为 200,MaxValue 设为 1000

MinValue和MaxValue除以5(这里只需要显示五个值)

下面是我实现的代码。

double initalValue = 200;
double finalValue = 1000;
double range = finalValue - initalValue;
double designCalRange = range/5;
double intialrange = initalValue;

System.out.println("designCalRange::>"+designCalRange);


System.out.println("AtuaValue::>"+Math.ceil(intialrange));
System.out.println("RoundOffValue::>"+Math.ceil(intialrange/100)*100 + "\n");

for (double i = 1; i<=5;i++){
intialrange += designCalRange;
System.out.println("\n"+"AtuaValue::>"+Math.ceil(intialrange));
System.out.println("RoundOffValue::>"+Math.ceil(intialrange/100)*100);
}
}

我的输出是**

RoundOffValue::>200.0
RoundOffValue::>400.0
RoundOffValue::>600.0
RoundOffValue::>700.0
RoundOffValue::>900.0
RoundOffValue::>1000.0

**

但应该是:

RoundOffValue::>200.0
RoundOffValue::>400.0
RoundOffValue::>600.0
RoundOffValue::>800.0
RoundOffValue::>1000.0

最佳答案

你是否期待像下面这样

更新为显示 5 个值

   public class Test {
public static void main(String[] args) {
int initalValue = 200 ;
int finalValue = 1000 ;
int range = finalValue - initalValue;
int designCalRange = range/4;
System.out.println("Dividing in to 5 equal intervals");
System.out.println(initalValue);
for (double i = 1; i<=3;i++){
System.out.println((int)(initalValue+designCalRange));
initalValue = initalValue+ designCalRange;
}
System.out.println(finalValue);
}
}

关于java - 计算最小值和最大值并四舍五入到近值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18740949/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com