[SOLVED] Why doesn't this code work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

[SOLVED] Why doesn't this code work?

I made this simple code but it doesn't run. When I added "String args[]" in the main method it works, but why won't it work without it? Why is "String args[]" necessary? https://code.sololearn.com/c3lPBe37hfU8/?ref=app

6th Jun 2022, 11:06 AM
Bhaveshsingh Pawar
Bhaveshsingh Pawar - avatar
4 Answers
+ 4
Java main method's syntax by Language implementation is public static void main(String arg[]) { // code } If you omit anything, then it's error or not a main method. You have a normal method named main() . No main method so it won't run, just compiles only.. Hope it helps...
6th Jun 2022, 11:35 AM
Jayakrishna 🇮🇳
+ 2
Google is your best friend. https://stackoverflow.com/questions/890966/what-is-string-args-parameter-in-main-method-java It's hard to completely illustrate since Sololearn isn't really an IDE and therefore doesn't have a proper terminal. But essentially it's needed to get input from the user.
6th Jun 2022, 11:11 AM
Justice
Justice - avatar
+ 2
User42 You always need arguments if you're getting user input. It's not an IDE thing, it's a Java language thing. I only pointed out SL not being an IDE because it doesn't have a proper command line to be able to see how it works.
6th Jun 2022, 11:27 AM
Justice
Justice - avatar
0
KAILASH KURMI to ask questions you should be asking them in separate newer thread of yours, not in other question's thread. It may not get noticed and solved on time. In case you don't know, HOW TO ASK A QUESTION IN SoloLearn: 1) Go to "discuss" tab/section. 2) Click "+". 3) Type your main query in the first text field. 4) Describe your problem further in the second text field. 5) If necessary, add/attach a code with "add code" button. 6) Add the relevant tags, like the language (C#,Java,Python, etc.), etc.
8th Jun 2022, 12:39 PM
Bhaveshsingh Pawar
Bhaveshsingh Pawar - avatar