• Register
0 votes
377 views

Problem :

I am trying to learn Java, I am very newbie however I wanted to know what I do to get the "run" it. I am facing below error:

Static Error: This class does not have a static void main method accepting String[].

Below is my code:

public class MyCaneirinho {
    public static void mycontar() {
        int j= 1;
        String x = " Carneirinho",
            y = " pulando a cerca.",
           z = "s";
        for (j = 1; j <= 100;j++) {
            if (j == 1) {
                System.out.println(j + x + y);
            } else {     
                System.out.println(j + x + y + z);
            }
        }
    }
} // MyCarneirinho

 

6 5 3
7,540 points

1 Answer

0 votes

Solution :

Any Java class that you want to run directly must have the main method, it is the entry point, i.e., the program starts with main() when you execute the code.

public static void main(String args[])

So your correct code should be as below :

public class MyCaneirinho {
   public static void mycontar() {
        int j= 1;
        String x = " Carneirinho",
            y = " pulando a cerca.",
           z = "s";
        for (j = 1; j <= 100;j++) {
            if (j == 1) {
                System.out.println(j + x + y);
            } else {     
                System.out.println(j + x + y + z);
            }
        }
   }
public static void main(String[] args){
   mycontar(); // call mycontar() from the main method
}
} // MyCarneirinho
9 7 4
38,600 points

Related questions

0 votes
1 answer 92 views
92 views
Problem : I am having following warning message. The serializable class does not declare a static final serialversionuid field of type long I would like to understand and resolve the issue. Can somebody explain me this issue with simple words? I know what OOPs is Please ... void main(String[] args) { SwingUtilities.invokeLater(new Runnable(){ public void run(){ createAndViewJFrame(); } }); } }
asked Nov 24, 2019 alecxe 7.5k points
0 votes
2 answers 330 views
330 views
Problem : I am unable to figure out what is wrong with my code. When I try to compile my code I get the below message: &ldquo;Program does not contain a static 'main' method suitable for an entry point&rdquo;
asked Jan 29 jwilliam 3.9k points
1 vote
1 answer 22 views
22 views
Problem: I am totally new in programming language. So I tried to write a program using: public static void main(String args[]) But it seems to give error : public static void main(String args[]) ^ IndentationError: unexpected indent What should I do?
asked Apr 2 LizzyM 6.1k points
1 vote
1 answer 18 views
18 views
Problem: I admit it that Java programming is fun but it seems confusing sometimes. I am trying to adopt somethings about method and object in java. I know how to create a method and calling it inside the main method. I have a very simple question, can a void ... have a return statement? What happens if I try to return values from a void method? A well-explanation is expected. Thanks again, guys.
asked Mar 30 Gavin 15.3k points
0 votes
2 answers 116 views
116 views
Problem : I am beginner in Android Studio and I have written code, but I keep facing below error if I try to run my code: "Error: method does not override or implement a method from a supertype". I have already spent over four hours on this error but I am unable to fix it. Can somebody help me in fixing this issue?
asked Feb 26 mphil 2.3k points