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

 

orion.a.smith@gmail.com apcsa-encryption > apcsaEncryptCaesarChar
prev  |  next  |  chance

Given an input char, return the result of a one-character Caesar cipher where any letter is shifted up one letter. Precondition: the input char will have only a capital letter in it.

HINT #1
You can convert a char to a numeric data type like int by using casting syntax. Then it can be played with like any other int. You can cast an int to a char, as well. Here's an example:
char a = 'A';
int numA = (int)a;
numA = numA + 3;
char newChar = (char)numA; // newChar == 'D'
HINT #2
The ASCII (also UTF-8, used by Java) number representing 'A' is 65. There are 26 letters in the English alphabet, which could either be represented by the numbers 1 to 26 or (sometimes more useful mathematically) 0 to 25. What output should you get when the input is 'Z'?

The most elegant solution will use the remainder operator %, instead of a conditional or a ternary operator.

apcsaEncryptCaesarChar("A") → "B"
apcsaEncryptCaesarChar("B") → "C"
apcsaEncryptCaesarChar("Z") → "A"

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

public char apcsaEncryptCaesarChar(char c) { }

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: 310

Copyright Nick Parlante 2017 - privacy