import java.util.Scanner;
public class Calculations {
public static void main (String [] args) {
Scanner console = new Scanner (System.in);
int a = 0;
int b = 0;
int sum = 0;
int product = 0;
System.out.println ("Enter the Lower Bound");
a = console.nextInt();
System.out.println("Enter the Upper Bound");
b = console.nextInt();
while (a <= b) {
product *= a;
sum += a;
a++;
}
System.out.println("The sum is " + sum);
System.out.println("The Product " + product);
}
}
当我使用+=
加法时,我得到a和b之间的加法结果。例如,如果a为2,b为5,则总和为14。当我*=
用于乘法时,得到零。我需要帮助以解决我将产品归零的问题。
什么时间0 0所以不要用开始product
的0
,开始1
。
int product = 1;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句