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

后端 未结 3 1439
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-12 07:29

I\'m learning, I\'m newbie but I wanted to know what I do to get \"run\" it. this happening a error:

Static Error: This class does not have a static void mai         


        
相关标签:
3条回答
  • 2020-12-12 08:06

    If you write a java program, it can have a number of classes but for all the classes to run we should have a main class which is used to implement the classes which we defined. You created a class without main in it. The program will start its execution from main.

    0 讨论(0)
  • 2020-12-12 08:07

    Any Java class that you run directly must have a main method, which is the entry point, i.e., where the program starts when you execute the code.

    public static void main(String args[])
    

    Just rename your method contar() to main(String args[]) and it should work.

    0 讨论(0)
  • 2020-12-12 08:20

    Alternate to @mellamokb Answer

    public class Caneirinho{
    
     public static void contar(){
       int i = 1;
       String a = " Carneirinho",
         b = " pulando a cerca.",
         c = "s";
    
       for(i=1; i<=100; i++){
         if(i==1){
           System.out.println( i + a + b );
          } else {     
            System.out.println( i + a + c + b ); 
            Thread.sleep(1000);  // thread wais for 1 sec ie 1000 milisecond    
          }     
        }
      }
    
    public static void main(String[] args){
       contar(); // call contar() from main method
    }
    
    }//Carneirinho
    
    0 讨论(0)
提交回复
热议问题