public static void main(String[] args) {
int lowerVal=1; int upperVal=100;
int sum=0;
for (int x = 0; x<=100; x++)
{
sum+=x;
}
double average =(lowerVal+upperVal)/2.0;
System.out.println("The sum is:"+sum);
System.out.printf( "The average is: (%d+%d)/2 = %.2f",lowerVal,upperVal,average);
}
使用java计算1到100的总和和平均值
最新推荐文章于 2023-02-13 17:48:16 发布