Greetings all,

I'm trying to use the Math.pow(2, b) in the following manner. The program prompts for a user input (int). It then takes the user int and puts it into a forumla that (amoung other things) computes the number 2 to the input's power. (Thus I'm using the Math.pow(2, b). The problem I'm having of course is one of accuracy with a compile time error. Math.pow wants to return a double, but my input is an int. I know I have to "cast", but I don't have a decent example of how to do a cast. Also, I'm using one file to keep my methods, and another file that actually runs the program. So would the cast go in the file with the method that does the calculation?

Let me try to explain. File 1 prompts the user for the input. The user enters a number. That number is passed to File 2 that has the method with the calculation. File 2 does the calculation, then passes the result back to the first file and displays the result to the user.

My 2 questions are:
1. Which file do I put the cast?
2. What is the syntax for the cast?


Thanks for your consideration,
Bud

Recommended Answers

All 2 Replies

(int)Math.pow ( 2, b ); // Cast the result of pow to int
(int)Math.pow ( 2, b ); // Cast the result of pow to int

Thanks for your help!


Bud

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.