English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Write a program called Decrypt, that reads a sentence from the standard input, keyboard input. The sentence has been encrypted as follows: only the first five even-numbered characters should be counted. Decrypt the sentence and output the result.
Sample Input:
Pleas enter encrypted string:
Hiejlzl3ow

Sample Output:
The decrypted string is: Hello

2007-03-16 06:49:14 · 2 answers · asked by LULU 1 in Computers & Internet Programming & Design

2 answers

This is not as hard as you think. Basically what they are asking is that you take every odd numbered letter. So you need one loop which iterates each letter of the sentence and if the counter of the loop is odd, pull the letter you are currently looking at. Append it to a string to print after the loop has ended. Once you have reached the end of the sentence or pulled five characters, exit the loop.

Here is a taste of the solution:

String mystr = new String("Hiejlzl3ow");

for (int i=0; i < mystr.length(); i++)
{

}

You can look at each character using mystr.charAt(i) in the loop.

Good luck on the test! We will be rooting for you.

2007-03-16 09:02:47 · answer #1 · answered by Martyr2 7 · 0 0

Why not tell us what you did so far and show us where your stuck and what errors you get. Seems like you want someone to post the answer (which won't help you in the long run).

2007-03-16 14:05:36 · answer #2 · answered by The First 3 · 0 0

fedest.com, questions and answers