2-2:编写一个Java应用程序,用户从键盘表只能输入整数,程序输出这些整数的乘积。

import java.util.*;
public class Example2_4{
  public static void main(String args[]){
    Scanner reader=new Scanner(System.in);
    int product=1;
    int total=0;
    System.out.println("请输入整数:");
    while(reader.hasNextInt()){
      int x=reader.nextInt();
      total=total+1;
      product=product*x;
    }
    System.out.printf("%d个数的乘积为%d\n",total,product);
  }
}

posted on 2013-03-07 20:46  Nephalem  阅读(1519)  评论(0编辑  收藏  举报

导航