+ 2

Call JAVA method!

Hi! I created a loop to print user's name as many times as he wants. I just began to learn methods, and I need an advice of experienced guys: How to turn it into the method and call it? Here is my code: https://code.sololearn.com/cYJYmckEMHnG Thanks a lot for help!

1st Feb 2018, 11:09 PM
DIY Mods
DIY Mods - avatar
11 Respuestas
+ 2
You need to use a code editor that can format your code for you. That would have gotten you past the first error: You had an extra "{". After that, you were trying to use variables that were declared in a different function. You need to do some research about scope. I moved the variables to the class level because that was the easiest to do on my phone. You also declared a function as void then tried to return a value from it. Void means it does not return a value. Based on your comments, it also sounds like you don't know how to pass parameters, or rather how to declare a function that takes parameters. You pass already pass parameters to some of the built in functions. I'm sure you can figure that out on your own. I'm running short on time here. https://code.sololearn.com/cmFAB1XgKzQ4/?ref=app
2nd Feb 2018, 4:38 AM
Jesse Bayliss
Jesse Bayliss - avatar
+ 1
"main" is the first function that gets called. You have to put your logic in there. You also had a line at the top that was stopping it from compiling. https://code.sololearn.com/c7TnG6kxAMQE/?ref=app
1st Feb 2018, 11:20 PM
Jesse Bayliss
Jesse Bayliss - avatar
+ 1
thanks a lot, buddy!
1st Feb 2018, 11:21 PM
DIY Mods
DIY Mods - avatar
+ 1
You didn't put in a line to print the surface area. The Surface function returns the value, but you don't assign it to anything so the value just gets lost.
2nd Feb 2018, 4:47 AM
Jesse Bayliss
Jesse Bayliss - avatar
+ 1
Yeah you can. You just have to add a System.out like I just did. Check the last code again.
2nd Feb 2018, 4:53 AM
Jesse Bayliss
Jesse Bayliss - avatar
0
Same thing. https://code.sololearn.com/c81JF6SymypN Cant create a method properly... I made a code and I'll figure it out how to do it tomorrow, just have to submit it asap. Please help! Thank you for your help! Much appreciated!
2nd Feb 2018, 3:59 AM
DIY Mods
DIY Mods - avatar
0
I can't thank you enough! You are the best! But it doesn't return Surface for some reason
2nd Feb 2018, 4:41 AM
DIY Mods
DIY Mods - avatar
0
damn. I have 12 minutes to fix it, and it's no way
2nd Feb 2018, 4:48 AM
DIY Mods
DIY Mods - avatar
0
Done! Brother, you saved me as Jesus :) All the best to you!
2nd Feb 2018, 4:59 AM
DIY Mods
DIY Mods - avatar
0
I normally don't like giving people homework answers, but you were 99% there. Also, I suggest playing around and trying to write some code for fun and not just sticking to the assignments. Trying to figure out solutions is what programmers get paid for.
2nd Feb 2018, 5:04 AM
Jesse Bayliss
Jesse Bayliss - avatar
0
I will. Just working like horse at two jobs and barely managing to finish assignments on time. I'll definitely will do it on spring break, I already have a project that I want to create. Thanks again!
2nd Feb 2018, 5:07 AM
DIY Mods
DIY Mods - avatar