简体   繁体   中英

Error when creating a Caesar Cipher Program in Java

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;
     }

     }

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()?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM