How to the get the absolute value of a number in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {
 
    public static void main(String[] args) {
        
        Integer i1 = -90;
        int i2 = -800;
        double d = -93.14;
        float f = -3000;  
        long l = -1234;
						
        System.out.println(Math.abs(i1));
        System.out.println(Math.abs(i2));     
        System.out.println(Math.abs(d));    
        System.out.println(Math.abs(f));    
        System.out.println(Math.abs(l));    
    }
}
 
/*
run:

90
800
93.14
3000.0
1234
 
*/

 



answered Sep 7, 2016 by avibootz

Related questions

1 answer 160 views
160 views asked Jun 29, 2015 by avibootz
1 answer 226 views
1 answer 152 views
1 answer 143 views
143 views asked Aug 5, 2020 by avibootz
1 answer 173 views
...