Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get return value from function.  RSS feed

 
Erdene Yadam
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know how to declare on line 7, 8.
also on line 4, 5 (The array is only written to, never read from)
 
Erdene Yadam
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot to write function on line 6.

I am trying to write program that combine 2 sorted arrays in 1 sorted array.
 
Junilu Lacar
Sheriff
Posts: 11144
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you're calling the merge method like that, you are already getting the result back. Your problem is that you're not putting that result anywhere. To do that, you need to assign it to a variable, much like what you're doing on lines 4 and 5. What you're doing on line 7 is wrong.
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a_array? b_array? What bad names for arrays. You cannot tell from reading those names what the arrays mean. Also because you used the same names as parameters in the merge method, you can confuse yourself into thinking they refer to the same things. You sh‍ould only use underscores in identifiers for package names of constants.
You will probably find easier ways to copy part of an array into another one if you use methods of the Arrays class or even this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!