How to fix this? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to fix this?

https://code.sololearn.com/c3WEZ52G7v1c/?ref=app i found out that i write 2 mains but it still doesn't work

25th Dec 2021, 2:59 PM
Max
Max - avatar
9 Answers
+ 4
Max We can do like this but Sololearn doesn't support Thread properly. We get all outputs only once. Thread test = new Thread () { public void run() { try { for (int i = 0; i < 10; i++) { System.out.println (i); Thread.sleep(100); } } catch ( InterruptedException e) { System.out.println("Error while calling sleep thread"); } } }; test.start();
25th Dec 2021, 7:35 PM
A͢J
A͢J - avatar
+ 4
I'm not a Java connoisseur, but is this programming language so permissive that it can have 2 main() functions?
25th Dec 2021, 3:03 PM
Romeo Cojocaru
Romeo Cojocaru - avatar
+ 4
Max What is start and why there are two main method? You cannot define class inside method. Method should be inside class.
25th Dec 2021, 3:06 PM
A͢J
A͢J - avatar
+ 1
A͢J Romeo Cojocaru how did i think that was right 😂
25th Dec 2021, 3:34 PM
Max
Max - avatar
+ 1
Max That is start method which should have parenthesis () A method should have parenthesis () we directly call static method through a class so here if start is a method in class A then start method should be static. So if you call A.start then it is wrong. Also start is a method of Thread class so there should be test.start() Also you cannot start same thread which is already started. https://code.sololearn.com/cGOm95K5olXZ/?ref=app
25th Dec 2021, 5:52 PM
A͢J
A͢J - avatar
+ 1
A͢J thank you very mich
25th Dec 2021, 7:54 PM
Max
Max - avatar
0
Max Now that you resolved the 2 main() functions thing, I don't think a class definition must be in the Program class. But, I was saying, I'm not familiar with Java syntax.
25th Dec 2021, 3:44 PM
Romeo Cojocaru
Romeo Cojocaru - avatar
0
@AJ now i saw that i didn't answer your question, sorry. Start executes the whole class, doesn't it?
25th Dec 2021, 4:09 PM
Max
Max - avatar
0
A͢J but do you know how to make the program wait before outputting?
25th Dec 2021, 7:06 PM
Max
Max - avatar