string s ="application"
int p=s.lastindexof('a')
system.out.println(Math.pow(p,3));
Answers
Answered by
4
Solution :
String s = "application";
int p = s.lastIndexOf('a');
System.out.println(Math.pow(p,3));
int p = s.lastIndexOf('a');
It returns 6 to the integer variable p.
.°. p = 6.
System.out.println(Math.pow(p,3));
We know that p = 6.
Math.pow(6, 3)
= 216.0
So,
String s = "application";
int p = s.lastIndexOf('a');
System.out.println(Math.pow(p,3));
Output : 216.0
Explanation :
- int lastIndexOf(char ch) is used to find the index of the last occurrence of a character in the String. Index counting starts from 0. So, counting the alphabets from ‘a’ as ‘0’ we get that the ‘6th’ index is having the last occurrence of ‘a’. So, p = 6.
- Math.pow() is used to find the power raised to a given value. Math.pow(6,3) will return 6³ = 6 × 6 × 6 = 216. But the final answer is 216.0 because Math.pow() always returns double type value.
- So, final output will be 216.0
Explore More :
- Java Class Library (JCL) contains a class called String which is available under java.lang package.
- A set of characters within double quotes is String.
- Like Math and Computer classes, String class also processes some useful functions to operate or manipulate String data.
- The library methods are the in–built methods designed by the developers.
Similar questions