要取变量a的绝对值应该用什么函数

解决方案 »

  1.   

    这个程序便宜为什么出错import java.lang.Math;public class Test
    {
    public static void main(String args[])
    {
    int x;
    x=-5;
    x = abs(x);
    System.out.println(x);
    }
    }
      

  2.   

    import java.lang.Math;public class Test
    {
    public static void main(String args[])
    {
    int x;
    x=-5;
    x = Math.abs(x);
    System.out.println(x);
    }
    }
      

  3.   

    用Math类中的abs方法 ,建议楼主去看看  
    Math类中的一些方法,相信对你很有用的
      

  4.   

    首先指出Math类是一个静态类,你要使用它的方法,可以直接用className.Method()即可..
      

  5.   

    import static java.lang.Math.*;
    public class Test
    {
    public static void main(String args[])
    {
    int x;
    x=-5;
    x = abs(x);
    System.out.println(x);
    }
    }
    这样也可以
      

  6.   

    我也试了,不行。错误提示:
    E:\java\A.java:6: cannot find symbol
    symbol  : method abs(int)
    location: class A
                    x = abs(x);
                        ^
      

  7.   

    Math.abs()如果你是在学习java的话
    建议下 java.api文档
    非常有帮助的
      

  8.   

    寂寞呆头鱼static import, 虽然好用省打字, 但用多了会影响程序的可读性, 毕竟大家都已经习惯了Math.method()了...