java is not passing values to main method | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

java is not passing values to main method

hello, good morning/afternoon/evening/night. check this code: https://code.sololearn.com/c53giTIx9zWE/#java Does anyone know why the value is not passing? main method and static method is not syncing/passing values. the value IS passing from the MAIN method to the CLASS method but it is NOT passing from the CLASS method to the MAIN method... Thank you... if anyone knows how to solve it, please share it :) have a great morning/afternoon/evening/night. happy coding!

21st Dec 2019, 10:57 PM
KingDaniel2004
KingDaniel2004 - avatar
5 Answers
+ 5
@Tibor Sanata do you mean like this? https://code.sololearn.com/c87zi9Vweqf9/#java
22nd Dec 2019, 1:04 AM
KingDaniel2004
KingDaniel2004 - avatar
+ 4
integer types are value based not reference based. Therefore if they get updated in a function-scope the update won't be passed to the global variable.
21st Dec 2019, 11:40 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
Mr. 🍊range Tibor meant like this: https://code.sololearn.com/cLm7OG7vJ6jZ but that doesn't solve the problem how you wanted it :( 🌟(Pro)metheus 🇸🇬 I just googled for an answer to op, and it says java always passes by value, no matter the type. That's very sad :( .
22nd Dec 2019, 6:27 AM
Selin Genkur
+ 1
You can declare your class variables outside of the main method (just after class testing). They need to be static too, as your methods, because you are not instantiating your testing class. In that case you don't even need to pass them to your add method as parameters, because the method can directly access and modify static class members (variables).
21st Dec 2019, 11:49 PM
Tibor Santa
Tibor Santa - avatar
+ 1
Mr. 🍊range You should read about pass by value and pass by reference. It will give you a better understanding.
22nd Dec 2019, 4:21 AM
Avinesh
Avinesh - avatar