kotlin - I don't know how to get Integers from another function without calling the variables that hold said number - St
- c - Solaris 10 make Error code 1 Fatal Error when trying to build python 2.7.16 - Stack Overflow 推荐度:
- javascript - How to dismiss a phonegap notification programmatically - Stack Overflow 推荐度:
- javascript - Get the JSON objects that are not present in another array - Stack Overflow 推荐度:
- javascript - VS 2015 Angular 2 import modules cannot be resolved - Stack Overflow 推荐度:
- javascript - Type 'undefined' is not assignable to type 'menuItemProps[]' - Stack Overflow 推荐度:
- 相关推荐
I am taking Google's Kotlin Basics course for Android development. I am now at a exercise that wants me to create a function that calculates the sum of whatever number two variables hold (there are three variables, which hold the numbers 10, 5, and 8 for this particular exercise.) and then allow println to print out a string that goes like: "$firstNumber + $secondNumber = $result".
Trouble is, those numbers are assigned to variables defined in another function, which after some trial and error I discovered I can't call into another function (Which would make the need for a second function obsolete anyway, I guess).
I do not wish for the straight awnser to my exercise of course, just a hint as to what I can do to get those numbers in the add() function, sum them up, and then somehow get the "val result" variable to get the sum and print it out.
This is the one thing I tried:
just straight up type "var sum = firstNumber + secondNumber", only to remember the course hasn't gone over declaring variables that can be used across functions (if such thing is even possible in Kotlin), and even then, how do I get "val result" to hold the same number as "var sum"? I don't know how to do that either (the course hasn't gone over something like that yet either).
I then executed it anyway, got some errors as expected, the most prominent of which was the one that of course told me I cannot just use the same variable defined in main() and expect the other function to know what the heck I was talking about.
Now I thought of a whole lot of other solutions, none of which got around the problem of not being able to transfer a number/Integer in one function to another without being able to define something like a global variable or whatever.
- 力压谷歌、苹果,微软凭什么成为软件霸主?
- 谷歌正在复制苹果模式?(图)
- 台北电脑展周二开幕:Windows 8成焦点
- [连载]巨头“心血之作”终失败(五):惠普TouchPad
- java - ChatResponse how to get the history of the ToolResponseMessage Spring ai - Stack Overflow
- amazon web services - azure pipeline ec2 inventory creation - Stack Overflow
- perl - How to embed Teraterm in a Visual Studio project - Stack Overflow
- AWS CloudFront occasionally does not send request to custom origin server - Stack Overflow
- material ui - Using ShadowDOM to address MUI 5 vs MUI 6 Compatibility Issue? - Stack Overflow
- C equivalent of C++ inline - Stack Overflow
- node.js - Cookies Blocked in Cross-Origin Requests Between Netlify Frontend(Reactjs) and Railway Backend (Node ts) - Stack Overf
- flutter - Connect user to stripe connect to allow him receiving money - Stack Overflow
- css - How can I apply a view-transition to my sidebar only? - Stack Overflow
- google sheets - shortest formula to get the last non zero value from column - Stack Overflow
- python - Call function from macos framework (e.g. IntelPowerGadget) - Stack Overflow
- How to Use GraalVM to Execute JavaScript Code Making REST Calls Using Java? - Stack Overflow
- Can't swap camera with AVCaptureMultiCamSession with SwiftAVKit for iOS - Stack Overflow