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?

10th Jan 2018, 1:45 PM
Nikky Quinn
Nikky Quinn - avatar
4 odpowiedzi
+ 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); } }
10th Jan 2018, 3:08 PM
Nikky Quinn
Nikky Quinn - avatar
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
10th Jan 2018, 2:38 PM
Nikky Quinn
Nikky Quinn - avatar
0
The actual output is an error at the moment...
10th Jan 2018, 2:39 PM
Nikky Quinn
Nikky Quinn - avatar
0
Ok, thank you Gordie! I will try to figure it out :)
10th Jan 2018, 3:03 PM
Nikky Quinn
Nikky Quinn - avatar