Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Caesar Cipher

843789Mar 28 2009 — edited Mar 28 2009
I'm trying to do a basic caesar cipher shift by 1. This is my code so far but its off by one letter. Could someone tell me whats wrong with it? Thx
	public void caesarCipher()
	{
		char[] letters = {'A','B','C','D','E','F','G','H','I','J','K',
				'L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
		for(int x=0; x<letters.length; x++)
		{
			int n=1;
			letters[x]=letters[(x+n)%26];
			System.out.print(letters[x]);
		}
	}
This is the output of this code:

BCDEFGHIJKLMNOPQRSTUVWXYZB
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 25 2009
Added on Mar 28 2009
2 comments
162 views