• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need some help with methods

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there!

Cant figure out how the return statement in method2 works. Should´nt it be something like : return (sum + "_greetings"); I know that the other method1 calculate it but how on earth does only the "n" result in 170 ? n = 10? n*k = 170..?

 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Ungerfält wrote:I know that the other method1 calculate it but how on earth does only the "n" result in 170 ? n = 10? n*k = 170..?



The "n" local variable of the method1() call is different from the "n" local variable of the method2() call. You do know why right?

Henry
 
Daniel Ungerfält
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now when you say it I realise that its a different "n" in the method2. Got confused by the indentical variblename. But I still cant se how (if we name the other int in method2 "x") that "x" is equal to n*k..
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In that class it is equal, because you are passing n * k as a parameter. If you call that method differently, then the n in that method would have a different value.
 
Daniel Ungerfält
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:In that class it is equal, because you are passing n * k as a parameter. If you call that method differently, then the n in that method would have a different value.




I understand what you are saying. I just does not feel straigt logical like other things do. Maybe my eyes will be clearer by time? Or is it just like java is built this way and doesn´t always seem straight logical? If we talk Java/coding in general?
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would be the same in any language which supports that sort of method/function/procedure calls.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic