## JAVA EXAMPLE PROGRAMS

Checkout for Promo Codes

# Program: How to get absolute value in java?

 Description: In mathematics, the absolute value (or modulus) |a| of a real number a is the numerical value of a without regard to its sign. So, for example, the absolute value of 3 is 3, and the absolute value of -3 is also 3. The absolute value of a number may be thought of as its distance from zero. Below example shows how to get absolute value using Math.abs() method.

 Code: ```package com.java2novice.math; public class MyAbsEx { public static void main(String[] args) { double a = -23.45; int b = 234; double c = 12.54; System.out.println("absolute value of a: "+Math.abs(a)); System.out.println("absolute value of b: "+Math.abs(b)); System.out.println("absolute value of c: "+Math.abs(c)); } } ```

 Output: ```absolute value of a: 23.45 absolute value of b: 234 absolute value of c: 12.54 ```

#### List Of All Math Class Sample Programs:

Knowledge Centre
Difference between Enumeration and Iterator
The functionality of Enumeration and the Iterator are same. You can get remove() from Iterator to remove an element, while while Enumeration does not have remove() method. Using Enumeration you can only traverse and fetch the objects, where as using Iterator we can also add and remove the objects. So Iterator can be useful if you want to manipulate the list and Enumeration is for read-only access.
Famous Quotations
Discipline is just choosing between what you want now and what you want most.
-- Unknown Author