How is the div function being ran 3 times by coding System.out.println???
I'm not actually calling the div function, I'm only asking the compiler to print out a / b, so why is it doing it 3 times? I don't understand how the compiler pulls all this stuff together.
Can somebody explain this to me in a little depth?
I don't understand
Under discussion
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Peter
11 August 2019, 15:19
There are three calls in the main method:
div(6, 3);
div(10, 6);
div(2, 4);
The program is calling the div method three times with different values.
+1
Gustavo Franceschini
11 August 2019, 02:31
What do you mean "you are not calling the div function"?. Of course you are :) The System.out.println is part of the function. When you call the function div, you ask the compiler to calculate c by cividing a/b AND to print the value. If your function was called with a return statement (without System.out.print), then you would have to write System.out.println(div(n1,n2)) on your main argument. But since you already asks your function to write the value of c on the screen, all you need to do is call div (n1,n2).
0
Brandon Nicolle
11 August 2019, 03:37
When I write System.out.println I don't have call the div function. I just tell the compiler to print a divided b. (a / b) Right? Maybe I'm overthinking, I'm just having some trouble understanding the classes and the words they consist of.
+1
Gustavo Franceschini
13 August 2019, 23:29
You are not coding System.out.println() 3 times, you are coding the div function 3 times, and this function has a command for System.out.println(). Just like Peter said above, there are 3 calls to the div function. Maybe you missed it?
+1