0

This is the image before I run code:

enter image description here

And this is the image after running the code:

enter image description here

Please help me.

I was expecting the code to be running but, it throws error.

rioV8
  • 24,506
  • 3
  • 32
  • 49

1 Answers1

1

You need a static void main() for your program to start:

public class print1_10 {

    public static void main(String[] args) {
        int counter = 1;
        while (counter < 11) {
            System.out.println(counter);
            counter++;
        }
    }

}

See this previous question for more information...

Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
  • If you think the answers to that other question also serve to answer THIS question, then you should vote to close this question as a duplicate, instead of answering it. – Dawood ibn Kareem Jan 17 '23 at 04:48
  • I think that other question has a lot of information, but none of them show a complete class with a `main()` in it, so I posted one here. – Idle_Mind Jan 17 '23 at 05:00
  • Sure. I was looking for an accurate duplicate question myself, because it seems to me that this particular question gets asked quite often. I didn't manage to find one, which suggests that it typically gets closed and deleted when someone asks it. Good point about clearly showing a `main()`. Here, have an upvote. – Dawood ibn Kareem Jan 17 '23 at 05:05
  • yes this is the correct answer for the question , you have to put your logic code inside the main method or create a separate method and call in main method – Ramanand Prajapati Jan 17 '23 at 05:22