Quick Print – Computer Sir Ki Class

Login


Lost your password?

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


Shop
siteicon
Solved Problem Solved Problem#JAVA#3964

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

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.