Who knows about Math.abs()? give me the outputs : | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Who knows about Math.abs()? give me the outputs :

Math.abs('-1'); Math.abs(-2); Math.abs(null); Math.abs(''); Math.abs([]); Math.abs([2]); Math.abs([1,2]); Math.abs({}); Math.abs('string');

30th Aug 2017, 10:53 AM
Rocky
5 Answers
+ 6
In Java:- Math.abs() function returns the absolute value of the number passed as argument i.e. either you enter a positive number or a negative number, it will always return a positive number... e.g. Math.abs(4) -> 4 Math.abs(-4) -> 4 Math.abs() takes only int,long,float and double as argument
30th Aug 2017, 11:07 AM
cHiRaG GhOsH
cHiRaG GhOsH - avatar
+ 6
@Prem Singh Rathore This was not a C++ question. Therefore I request you to remove the c++ tag as that is misleading...
30th Aug 2017, 1:40 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 5
@prem_singh .......thanks bro..:D
30th Aug 2017, 11:19 AM
cHiRaG GhOsH
cHiRaG GhOsH - avatar
+ 3
Very well explained..
30th Aug 2017, 11:18 AM
Rocky
+ 1
@Kinshuk did it bro... appreciate it.
30th Aug 2017, 1:48 PM
Rocky