0

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 main method accepting String[].

This is the code:

/**
 * @author "LionH"
 */
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);
            }
        }
    }
} // Carneirinho
Marcelo
  • 2,232
  • 3
  • 22
  • 31
Falmer
  • 17
  • 1
  • 1
  • 2

3 Answers3

6

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.

mellamokb
  • 56,094
  • 12
  • 110
  • 136
  • Thanks already managed to fix the error, excuse the stupid question, but as I said I'm learning, one more doubt: as increasing the time interval? Sorry for my english, I'm learning too and once again thank you! – Falmer Feb 02 '13 at 00:26
  • Time interval of what? How long between each iteration of the `for` loop? Does the content scroll by too fast and you want to see it all or something? – mellamokb Feb 02 '13 at 02:26
3

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
Smit
  • 4,685
  • 1
  • 24
  • 28
  • Thanks already managed to fix the error, excuse the stupid question, but as I said I'm learning, one more doubt: as increasing the time interval? Sorry for my english, I'm learning too and once again thank you! – Falmer Feb 02 '13 at 00:25
  • @user2034259 What do you mean by ---> `one more doubt: as increasing the time interval?` – Smit Feb 02 '13 at 00:28
  • more time between one and the next. – Falmer Feb 02 '13 at 00:43
  • @Falmer I still unable to understand your question! :-( – Smit Feb 02 '13 at 00:52
  • @Falmer Do you mean to say what time difference it will make if you apply my answer and mellamokb answer? Am I correct predicting your question? – Smit Feb 02 '13 at 01:16
  • no, i want to know how do I make for my "program" have a greater time difference, when you press "Run". – Falmer Feb 02 '13 at 02:11
  • @Falmer I updated the answer. You can make use of `Thread.sleep()` if you want some time delay between printing the values. `Thread` is kinda complex and vast area. However it will solve your issue. – Smit Feb 04 '13 at 17:16
0

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.

user1658435
  • 574
  • 1
  • 9
  • 28