I'm not quite sure I understand your question there. What do you mean by "accept any a, b and c"? Do you mean that the datatype of the a, b, and c parameters is unknown?
Woops. I think it needs to accept variables a, b, and c to which different values can be assigned. I guess.
I have had a crazy fucking weekend/Monday and I'm more or less unable to focus on this for some reason. I pulled this out of my ass after looking at various examples in my text:
Oh, I'll look at the algorithm for a bit later, haven't had enough tea yet. I think a quadratic equation can have more than one solution, so you might have to return an array. Do we assume the other side of the equation is 0?
I... Don't know? :X I doubt it was much more complicated than that. The homework is usually just a simple review of the basic things covered in the lecture, but I missed the lecture today so I'm more than a little confused.
Ah - can you check the lecture notes? It sounds like the idea was to talk about arguments and return variables, so that's what you should probably focus on :)
That would be fine, but we haven't done any if ___ then do ___ type things yet. We just barely started Java a little while ago and have barely covered anything.
Hrm, too weird, it sounds kind of basic to me. But I guess to each teacher their own style :) Anyway, use the Max function since it exists and it's probably faster anyway. Library functions often are.
Math.abs(number) gives the absolute value of a number*.
So...
public int largerAbsVal(int a, int b){
return Math.max(Math.abs(a),Math.abs(b));
}
*'number' in this case means short, long, int, float, or double.
Reply
Reply
Reply
;)
Reply
I have had a crazy fucking weekend/Monday and I'm more or less unable to focus on this for some reason. I pulled this out of my ass after looking at various examples in my text:
static double root(double A, double B, double C)
{
double disc = B*B - 4*A*C;
return (-B + Math.sqrt(disc)) / (2*A);
}
}
Reply
;)
Reply
Do we assume the other side of the equation is 0?
;)
Reply
Reply
;)
Reply
Reply
;)
Reply
Reply
if (abs(a)>abs(b)) {return a;} return b;
?
Reply
Need. More. Tea.
Reply
Reply
Anyway, use the Max function since it exists and it's probably faster anyway. Library functions often are.
;)
Reply
Leave a comment