JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

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
 Next Program >>

List Of All Math Class Sample Programs:

  1. How to get absolute value in java?
  2. How to get cube root of a value in java?
  3. How to get ceiling value of a number in java?
  4. Example for Math.copySign() method.
  5. How to get exponential value of a number in java?
  6. Example for Math.expm1() method.
  7. How to get floor value of a number in java?
  8. How to get max number between two numbers?
  9. How to get min number between two numbers?
  10. Example for Math.pow() method.
  11. How to calculate the length of hypotenuse in java?
  12. How to calculate exponent of the given number?
  13. How to calculate natural logarithm value of a number in java?
  14. How to calculate base 10 logarithm value of a number in java?
  15. Example for Math.nextAfter() method.
  16. Example for Math.nextUp() method.
  17. How to get random number between 0 to 1 in java?
  18. Example for Math.rint() method.
  19. How to round-off decimal number to nearest integer in java?
  20. Example for Math.signum() method.
  21. How to get square root of a number in java?
  22. How to convert an angle from radians to degrees?
  23. How to convert an angle from degrees to radians?
  24. How to calculate trigonometric sine of an angle in java?
  25. How to calculate trigonometric cosine of an angle in java?
  26. How to calculate trigonometric tangent of an angle in java?
Knowledge Centre
What is OOPs?
Object oriented programming organizes a program around its data, i.e. , objects and a set of well defined interfaces to that data. An object-oriented program can be characterized as data controlling access to code.
Famous Quotations
I respect faith, but doubt is what gets you an education.
-- Wilson Mizner

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2022 by Nataraja Gootooru. All Rights Reserved.