Java math function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Java math function

how I can generate a math function, like x^2 , x+5 and x^3+2 .

5th Feb 2018, 8:05 PM
D A Z A I ~
D A Z A I ~ - avatar
4 Answers
+ 1
So I answer what you asked and you down vote my answer because I didn't answer what you were thinking in your head but failed to put in your post? Nice, can't wait to help you out further and in the future. Best of luck to you.
6th Feb 2018, 8:43 PM
Fata1 Err0r
Fata1 Err0r - avatar
0
Below is the code you can use to obtain the power of the numbers. In my own test, I gave the X a value of 3 and the power a value of 3. The result was 27. The addition portion of your question is just as easy as adding it to the equation in your code. Example: x + 5 is easily done as x += 5; Let me know if you need further clarification. Hope this helps. https://code.sololearn.com/c2B2vhW4mkVf/#java import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); double x = 0; double exp = 0; double result = 0; System.out.println("Input X value: "); x = scnr.nextInt(); System.out.println("Input power: "); exp = scnr.nextInt(); result = Math.pow(x, exp); System.out.println("Result is: " + result); } } // OUTPUT:::: Input X value: 3 Input power: 3 Result is: 27.0
5th Feb 2018, 8:19 PM
Fata1 Err0r
Fata1 Err0r - avatar
0
I need more than power function. Its only a part of my program . I want to use that function to calculate the area between two curves using Riemann sums.
5th Feb 2018, 8:27 PM
D A Z A I ~
D A Z A I ~ - avatar
0
Thanks for everything. I use your code in my program and it’s really useful. Sorry if I was rude yesterday ;(
6th Feb 2018, 9:00 PM
D A Z A I ~
D A Z A I ~ - avatar