Fiveable
Fiveable

abs(int a)

Definition

The abs() function is used to find and return the absolute value (magnitude) of an integer. It disregards any negative sign attached to it and always gives back its positive equivalent.

Analogy

Think about temperature - whether it's hot or cold doesn't matter, what matters is the absolute value of the temperature. The abs() function works similarly by stripping away any negative sign and giving you the positive value.

Related terms

max(int a, int b): This method returns the larger of two given integers.

min(int a, int b): This method returns the smaller of two given integers.

random(): This method generates a random number between 0.0 (inclusive) and 1.0 (exclusive).

"abs(int a)" appears in:

collegeable - rocket pep

Are you a college student?

  • Study guides for the entire semester

  • 200k practice questions

  • Glossary of 50k key terms - memorize important vocab



© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.


© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.