-1

I am trying to create a program that changes 'a' to 'd', 'b' to 'e', etc. I have written some code and keep getting this error message:

Error: Main method not found in class ec1, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application

Here is my code:

public class ec1 {
   private String ALPHABET = "abcdefghijklmnopqrstuvwxyzabc";

   public String encrypt()
     {
         Scanner scan2 = new Scanner(System.in);
            System.out.println("Enter your message");
            String poop = scan2.toString();

            int key = 3;

            String code="";
           for(int i=0;i<poop.length();i++)
           {
                int a = ALPHABET.indexOf(poop.charAt(i));
                int keyVal = (key+a)%26;
                char replaceVal = this.ALPHABET.charAt(keyVal);
                code += replaceVal;
           }
           return code;
     }

     }
vefthym
  • 7,422
  • 6
  • 32
  • 58
WonderphuL
  • 57
  • 8

1 Answers1

3

JVM searches for the main() method to start the execution. so the control starts from there, you need to add main() method to your class and call the encrypt() method inside it.

   public static void main (String[] args) 
    {
     ec1 obj=new ec1();
     String encrypted_value=obj.encrypt();
    }

Read The Java Main Method and also Entry point for Java applications: main(), init(), or run()?

Community
  • 1
  • 1
Santhosh
  • 8,181
  • 4
  • 29
  • 56
  • ok where should I place that method? fairly new to coding only been a couple of months – WonderphuL Nov 04 '14 at 14:20
  • @WonderphuL Inside your class `ec1` wrap it to the beginning or the end – Santhosh Nov 04 '14 at 14:21
  • I put in the main method you posted and now the code is being terminated after outputting the scanner. Also it says String encrypted_value=obj.encrypt(); is not being used – WonderphuL Nov 04 '14 at 14:28