Java

  1. Home
  2. Computing & Technology
  3. Java
photo of Paul Leahy

Paul's Java Blog

By Paul Leahy, About.com Guide to Java

Monday's Programming Question

Monday October 6, 2008

Last week the challenge was to make a decoding program. It would seem silly not to make the encoder that goes with it.

Here's the same letter switch code:

Decodedabcdefghijklm
Encodedprjitgcoxbsyn
Decodednopqr stuvwx yz
Encodedwdemh uvlzfq ka
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.

This week write an encoder along the same principles of the decoder, except I want to highlight the difference between using a normal for loop and a "for each" loop. Your program should take a line of text entered by the user, use a combination of a for each loop and switch statement to encode it, and finally display the encoded line to the user.

The question is can your program encode this line?

it was a dark and stormy night

Comments

No comments yet. Leave a Comment

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Discuss

Community Forum

Explore Java

About.com Special Features

Java

  1. Home
  2. Computing & Technology
  3. Java

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

All rights reserved.