Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+14 votes
asked in CSC211_Winter2018 by (1 point)

2 Answers

+12 votes

If I start at the top of main, the variable one stores the string "two", the variable two stores the string "three", the variable three stores the string "1", and the variable number stores the integer 20.

The call sentence(one, two, 3) passes "two", "three", and 3 to the formal parameters three, one, and number. The formal parameters are different memory locations than those in scope in main. The formal parameter three stores "two", the formal parameter one stores "three", and the formal parameter number stores 3. Using those values, the println statement in the sentence method outputs "three times two = 6" (although in Practice It you don't enter in the quotation marks with the answer).

This is what Evan is saying, but I think including the quotation marks with the strings makes it clearer.

answered by (1 point)
+3

Thanks Prof. Mueller!

+10 votes

Well you have to look at the public static void sentence to get the output. That is a formal parameter. You can trace it by looking at the variables to.
For example sentence(one, two, 3)
You First look at one the variable in the parameter it is String three so it is just three you need the times because its in quotations then you would look at String one because it's in the Parameter, which is two not the number 2 but two, the you have the = (3*2) which is 6.
I hope this helps.

answered by (1 point)
+4

Thank you!

...