0
basicMathOperations
Hey there, First of all, I’m fairly new to this! :) I have a question about a problem I solve on my own. I was playing around with a code on basicMathOperations. After I managed to set up methods for +,-,* — calculations,🙆🏼♀️ I got to the division. This method works perfectly fine if the first number is bigger than the second one. The other way around will not work (Note on the side: all methods will only take in 2 parameters). Could somebody please help me?
7 ответов
+ 1
One of my friends and I just figured it out together... now it works!
static double divide(double val1, double val2){
return val1 / val2;
}
public static void main(String[ ] args) {
double x = divide(3,10);
System.out.println(x);
}
}
0
static double divide(double val1, double val2){
if (val1>val2){
return val1 / val2;
}
if (val1<val2){
return val1 / val2;
}
}
public static void main(String[ ] args) {
int x = divide(3,10);
System.out.println(x);
}
}
// Output: 0.3
0
The actual output is an error at the moment...
0
Ok, thank you Gordie! I will try to figure it out :)