there is a problem with java code

i need your help plz as soon as you can

import javax.swing.*;
	   import java.io.*;
	/**
	*Homework #1 CaesarCipher.java
	*program to encrypt and decrypt stuff
	*/
          
	public static void main(String[] args) {
			ceasar1 cc = new ceasar1();

	   public class ceasar1
	   {
	      public String dataencyptS, sInt;
	      public int offsetI;
	 
	      public void main(String [] args)	      {

	         dataencyptS=JOptionPane.showInputDialog("Input Data to encypt:");
	         sInt=JOptionPane.showInputDialog("Input the key offset:");
	 
	         offsetI = Integer.parseInt( sInt );
	      }
	 
	 
	      private void translate(int offsetI) {
	         char c;
	         while ((byte)(c = getNextChar()) != -1) {
	            if (Character.isLowerCase(c)) {
	               c = rotate(c, offsetI);                
	            }
	            System.out.print(c);
	         }
	      }
	 
	 
	      public char getNextChar() {
	         char ch = ' ';
	         try {
	 
	            ch =(char)dataencyptS.read();
	         } 
	            catch (IOException e) 
                    {
	               System.out.println("Exception reading character");
	            }
	         return ch;
	      }
	   // rotate: translate using rotation, version with table lookup
	      public char rotate(char c, int offsetI) { // c must be lowercase
	         String s = "abcdefghijklmnopqrstuvwxyz";
	 
	         int i = 0;
	         while (i < 26) {
	           // extra +26 below because key might be negative
	            if (c == s.charAt(i)) 
	               return s.charAt((i + offsetI + 26)%26);
	            i++;
	         }
	         return c;
	      }	 
	 
	 
	   }

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

Attachments 2011-03-20_213021.png 21.26 KB
public class ceaser1
{
........
........


........

public static void main( String [] args )        // Write main Inside class ceaser1
{
     ceaser1 c = new Ceaser1();
}
.............

.............
.............
}

And give details of what you're trying to do...

your program has more errors ---

public char getNextChar() {
char ch = ' ';
try {

ch =(char)dataencyptS.read();     // error in read() method as there is no read() method
}
catch (IOException e)
{
System.out.println("Exception reading character");
}
return ch;
}

thank u but i am trying to do caesar cipher by java program

encrypt and decrypt using caesar cipher

this is my question !

This article has been dead for over six months. Start a new discussion instead.