0

# Java math function

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

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.

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 ;(

Hot today

Please help, any idea?

2 Votes

Loop question, I've tried everything that I knew I just don't know. Please help me solve it out

1 Votes

What is wrong? Error on test.

1 Votes

Help me solve this (using loop)

1 Votes

Help me wiht python

1 Votes

how can i flip any word with c++

0 Votes