id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

CaesarCipher


A Caesar cipher is a rudimentary encoding scheme in which each letter is replaced by the letter occurring a given number of places after it in the alphabet. (Imagine that the letters are listed in a circle so that A immediately follows Z.) The given number is referred to as the shift because, in effect, a Caesar cipher shifts all the letters of the alphabet that many positions. For example, a shift of 2 would encode an 'A' as a 'C', a 'B' as a 'D', ..., an 'X' as a 'Z', a 'Y' as an 'A', and 'Z' as a 'B'. The notion of a negative shift makes sense too. Develop a method that accepts as input a shift value and a message. The shift value will be no less than -25 and no greater than 25. Any character that occurs in the message and that is not an upper case letter should be encoded as itself.


CaesarCipher(0, "HELLO") → "HELLO"
CaesarCipher(1, "ABCDE") → "BCDEF"
CaesarCipher(-1, "ABCDE") → "ZABCD"

...Save, Compile, Run (ctrl-enter)

public String CaesarCipher(int shift, String message) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 200

Copyright Nick Parlante 2017 - privacy