0
Java math function
how I can generate a math function, like x^2 , x+5 and x^3+2 .
4 ответов
+ 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.
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
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.
0
Thanks for everything.
I use your code in my program and it’s really useful.
Sorry if I was rude yesterday ;(