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
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();
+ 4
I'm not a Java connoisseur, but is this programming language so permissive that it can have 2 main() functions?
+ 4
Max
What is start and why there are two main method?
You cannot define class inside method. Method should be inside class.
+ 1
A͢J Romeo Cojocaru how did i think that was right đ
+ 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
+ 1
A͢J thank you very mich
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.
0
@AJ now i saw that i didn't answer your question, sorry. Start executes the whole class, doesn't it?
0
A͢J but do you know how to make the program wait before outputting?