+ 1
[ANSWERED]Method inside main
I get errors when creating those. Can I really not create methods inside main? I need to include the data inside the main (which has to be in main because it includes creating objects from an outer class).
8 Respuestas
+ 1
Do you mean creating methods in public static void main(String[] args) ?
+ 1
Here's an example of passing data from main and retrieving it back.
https://code.sololearn.com/c4cUSQN6uuAC/?ref=app
+ 1
Looks good. The code that you want to implement, i think its possible, I'll see if i can implement it in some way.
0
@Hassie
I do.
0
ok, yeah you can't create a method within a method.
That would be true for any Programming language.
You declare all methods in classes.
Note: Because main is a static method, you must make any methods static to use them in the main static method.
What you can do is create methods which take in parameters and return the value. I'll create a simple code and link it.
0
@Hassie
You mean setters and getters stuff?
0
You could do, by creating variables which are accessible by the whole class.
Or just create function methods, pass the values as parameters and return the value back.
0
@Hassie
Would you take a brief look at my code? There are many repetitious elements but it's short indeed without repetition.
https://code.sololearn.com/c6Sx0C18ue7W/?ref=app