for(int j=1;Math.abs(Math.pow(x,2*j)/m)>=0.000001;j++){
       m = m*2*j*(2*j-1);
       System.out.println("m="+m);
       y = 1+(-1)*s*Math.pow(x,2*j)/m;
       System.out.println("Y="+y);
      }
看看结果,溢出了!

解决方案 »

  1.   

    还有一个问题,关于switch-case 语句的
    case后面的常量表达式包括int,char,byte和short,
    但String 也行吗!?
      

  2.   

    case 后面是常量表达式,所以应该可以是String,楼主可以编程试试啊
      

  3.   

    啊,不好意思,我也刚刚编了一下,好象在java中比较不行的,真的不好意思,脸红一下
      

  4.   

    double x,y=0;
    int s=-1;  //s初始值为-1
    long m=1;   //m数据类型改为long,溢出主要在此,其他为逻辑错误.
    double temp=1;
    try{
    System.out.println("Please enter the value of x:");
    BufferedReader a = new BufferedReader(new InputStreamReader(System.in));
    x = Double.parseDouble(a.readLine());
    y=1; for(int j=1;Math.abs(Math.pow(x,2*j)/m)>=0.000001;j++){
                     m = m*2*j*(2*j-1);
                     y = y+s*Math.pow(x,2*j)/m;
                     s=s*(-1);   //加上这句                  /*
                      为防止溢出,可以加上:
                            if(Double.isInfinite(y)){
    System.out.println("overflow");
    break;
           }
                      */
              }
              .....