Using Math.pow and indexOf – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Exam Questions-ICSE2015-02C #JAVA#3964    siteicon   siteicon  

Problem Statement - Using Math.pow and indexOf

What is the value stored in variable res given below:
double res = Math.pow(“345”.indexOf(‘5’), 3);

Solution

TC++ #3964

double res = Math.pow(“345”.indexOf(‘5’), 3);

Here we will first calculate “345”.indexOf(‘5’)    as the first index starts 0 the index of ‘5’ in “345” would be 2. Now we place it in the method as follows.

Math.pow(2,3) = 2^3

So res = 8.0   //.0 is added as the variable type is double.


Share

sunmitra| Created: 22-Mar-2018 | Updated: 16-Apr-2019|ICSE2015






Back