We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Math.pow() is a function that is provided to us by Java. Here, it takes 2 parameters. When I pass in 2 and j, it does exponentiation (known as "power") as 2 to the j-th power. For example, Math.pow(3,5) = 3 * 3 * 3 * 3 * 3.
Also, Math.pow() returns a double instead of an int. We "cast" it to an integer by putting
(int)
in front of it. We cast our result since a is an integer type and we can only assign an int type to it.
Java Loops II
You are viewing a single comment's thread. Return to all comments →
is shorthand for
Math.pow() is a function that is provided to us by Java. Here, it takes 2 parameters. When I pass in 2 and j, it does exponentiation (known as "power") as 2 to the j-th power. For example, Math.pow(3,5) = 3 * 3 * 3 * 3 * 3.
Also, Math.pow() returns a double instead of an int. We "cast" it to an integer by putting
in front of it. We cast our result since a is an integer type and we can only assign an int type to it.
Hope this helps.
HackerRank solutions.