SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Barbara Dolye
Chapter:
Methods And Behaviors
Exercise:
Exercises
Question:23 | ISBN:9781285096261 | Edition: 4

Question

What will be produced from the following predefined Math class method calls?
a. Console.WriteLine(Math.Abs(-98887.234));
b. Console.WriteLine(Math.Pow(4,3));
c. Console.WriteLine(Math.Sign(-56));
d. Console.WriteLine(Math.Sqrt(81));
e. Console.WriteLine(Math.Min(-56, 56));

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

a)

The method call " Math.Abs(-98887.234)"  is "Abs" function under the Math Class.

  • This "Abs"  function is used to return the absolute value of a specified number.
  • It returns the 32-bit signed integer say r, such that 0 ≤ r ≤ Int32.
  • The statement "Console.WriteLine" print the result on screen. 

So, the statement Console.WriteLine(Math.Abs(-98887.234)) displays the output result is 98887.234

b)

The method call "Math.Pow(4,3) " used "pow" function. 

  • This 'pow'  function is used to compute a number raise to the power of some other number. 
  • Here pow(4,3)=44=64. 
  • The statement "Console.WriteLine" prints the result on screen. 

So, the statement Console.WriteLine(Math.Pow(4,3)) displays the output result is 64.

c)

The method call "Math.Sign(-56) "  used "sign" function.

  • This 'sign' function returns the integer that specifies the sign of a 32-bit signed integer.
  • The statement "Console.WriteLine" display the result on screen.   

So, the statement Console.WriteLine(Math.Sign(-56))  display the output result is -1.

d)

The method call " Console.WriteLine(Math.Sqrt(81)); " used "Sqrt" function.

  • This "sqrt" function is used to compute the square root of the specified number. \sqrt{81}=9.
  • The statement "Console.WriteLine" display the result on screen. 

So, the statement "Console.WriteLine(Math.Sqrt(81))" displays the output result is 9.

e)

The method call "Math.Min(-56, 56)" is used "Min" function.

  • This "Min" function is used to returns the smaller of the two specified numbers.
  • Here, Min(-56, 56) returns minimum value, -56.
  • The statement "Console.WriteLine" display the result on screen. 

So, the statement "Console.WriteLine( Math.Min(-56, 56) )" displays the output result is -56.

 

 

Sample C# executable code by using given statements:

OUTPUT:

 

0 0

Discussions

Post the discussion to improve the above solution.