JAVA应用程序 用户从键盘只能输入整数,程序输出这些整数的乘积。 我写的但是不能输出这些整数的乘积,求解? import java.util.*; public class Product{ public static void main(String args[]) { Scanner reader=new Scanner(System.in); int Product=0; int i=0; while(reader.hasNextInt()){ int n=reader.nextInt(); i=i+1; Product=Product*n; } System.out.printf("%d个整数的积为%d\n",i,Product*i); } }
Scanner reader = new Scanner(System.in);
int product = 1;
int i = 0;
while (reader.hasNextInt()) {
int n = reader.nextInt();
i = i + 1;
product = product * n;
}
System.out.printf("%d个整数的积为%d\n", i, product);
------解决方案--------------------
怎么可能执行下面的system.out呢!!
------解决方案-------------------- public class Product { public static void main(String args[]) { Scanner reader = new Scanner(System.in); int Product = 0; int i = 0; while (reader.hasNextInt()) { int n = reader.nextInt(); i = i + 1; Product = Product * n; if(n==5){ break; } } System.out.printf("%d个整数的积为%d\n", i, Product * i); } }