1. Home
  2. Computing & Technology
  3. Java

Encoded First Line

By , About.com Guide

Level: Beginner

Focus: Loops, Switch statement, Scanner object

Encoded First Line Question

Ever thought of becoming a spy? No, me neither. Still, I always liked the part about passing secret messages from one person to another. In this exercise you will need to write a decoding program to be able to answer the question.

I'm looking for a simple solution that takes a line of encoded text entered by the user and uses a combination of a normal for loop and switch statement to decode it. Finally, it will display the decoded text to the user.

The code is a simple letter switch as outlined in the table below. For example, the name "bob" becomes "rdr" (i.e., b=r, o=d, b=r). Don't worry about capital letters, just assume that all of the text is in lowercase.

The question is can your program decode this first line from a book by Iain Banks?

xv fpu vot ipk nk chpwindvoth tqeyditi

To get the most out of this question try and figure out the answer before coming back to read the solution on the next page.

Letter Switch
Decodedabcdefghijklm
Encodedprjitgcoxbsyn
Decodednopqr stuvwx yz
Encodedwdemh uvlzfq ka
Explore Java
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Java
  4. Programming Exercises
  5. Beginner Level
  6. Encoded First Line>

©2009 About.com, a part of The New York Times Company.

All rights reserved.