how to write the math function f(x) with Java
where f(x) = y

you may want to
1. check the Math class and see if there's anything in there that can help you
2. if it doesn't try to write a method yourself
3. if you can't figure out what the code should be: be a bit more clear about what you expect it to do

I did not see anything in the math class here, but you may want to double check:
http://download.oracle.com/javase/6/docs/api/java/lang/Math.html

But if I'm correct f(x) = y is very vague and just means x=y because you are not actually giving us a function to apply to x.

For example: We will use this set of inputs for x , x = {1,2,3,4,5} for both of the following problems.
f(x)=y
f(1)=1
f(2)=2
f(3)=3
f(4)=4
f(5)=5
The output(y) is the same as the input(x) because there is no defined function here.

Where as if it were something like this:

f(x+1)= y
f(1+1)=2
f(2+1)=3
f(3+1)=4
f(4+1)=5
f(5+1)=6

The output(y) has +1 added to each of the input(x).

I think he's just saying he wants a method f where he passes a param x, he just doesn't specify what the function is supposed to do.

Whoops, sorry! Misunderstood the question.

nja, it's not very clear

Member Avatar for hfx642

I think that this is a teaching moment here...

public int f (int x)
{
   int y;
   y = x;  // put your function here
   return y;
}

Change your data types to what you require.

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.