• Register
0 votes
797 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

Please log in or register to answer this question.

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 3 views
3 views
Problem: I was recently asked in an exam if public static void main(String arg[]) format of main method was fixed? Can we change it? Can we use main without any of public, static or void?
asked Apr 19 ummesalma 29.2k points
0 votes
1 answer 9 views
9 views
Problem: How can you explain very well, to a beginner, the meaning of String args[] and the use of static in the following excerpt? class FirstApp { public static void main(String[] args) { ... } }
asked Apr 20 munim01 21k points
0 votes
1 answer 14 views
14 views
Problem: Can anyone tell me the solution of this problem? public static void main string args meaning
asked Mar 26 Ifra 37.2k points
0 votes
1 answer 17 views
17 views
PROBLEM : Is there anyone to helo on > 'java public static void main(string args)' ?
asked Mar 16 Samiur1 38.4k points
1 vote
1 answer 53 views
53 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, 2020 LizzyM 6.1k points
1 vote
1 answer 4 views
4 views
Problem: I am unable to find out the solution, Please solve it : public static void main string args
asked Mar 31 MUHAMMAD MUNEEB 83k points
1 vote
1 answer 4 views
4 views
Problem: Please help me to solve it out : public static void main(string args)
asked Mar 31 MUHAMMAD MUNEEB 83k points
1 vote
1 answer 3 views
3 views
Problem: Why I got the error : public static void main(string args) explain
asked Mar 31 MUHAMMAD MUNEEB 83k points
1 vote
1 answer 2 views
2 views
Problem: How can I deal with this problem : public static void main(string args) in java
asked Mar 31 MUHAMMAD MUNEEB 83k points
1 vote
1 answer 3 views
3 views
Problem: I need a help , How I can fix this : public static void main(string args) java
asked Mar 31 MUHAMMAD MUNEEB 83k points