集册 Java实例教程 使用Math.abs查找float,int,double和long的绝对值

使用Math.abs查找float,int,double和long的绝对值

欢马劈雪     最近更新时间:2020-01-02 10:19:05

586
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用Math.abs查找float,int,double和long的绝对值
//来 自 NowJava.com


public class Main {

 

  public static void main(String[] args) {

   

    int i = 8;

    int j = -5;

   

    System.out.println("Absolute value of " + i + " is :" + Math.abs(i));

    System.out.println("Absolute value of " + j + " is :" + Math.abs(j));

   

    float f1 = 10.40f;

    float f2 = -50.28f;

 

    System.out.println("Absolute value of " + f1 + " is :" + Math.abs(f1));

    System.out.println("Absolute value of " + f2 + " is :" + Math.abs(f2));

   
   /*
   N o w  J a v a  . c o m 提 供
   */

    double d1 = 43.324;

    double d2 = -349.324;

    System.out.println("Absolute value of " + d1 + " is :" + Math.abs(d1));

    System.out.println("Absolute value of " + d2 + " is :" + Math.abs(d2));

   

    long l1 = 34;

    long l2 = -439;

    
展开阅读全文