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-07 16:08:52 · 2 answers · asked by LULU 1 in Computers & Internet Programming & Design

2 answers

import java.io.*;
import java.util.*;

public class Decrypt
{

static java.io.InputStream f= java.lang.System.in;
public static void main(String[] args) throws Exception
{

String text;
BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
text = BR.readLine();
StringBuffer dtext = new StringBuffer();
for(int c=1;c<=9;c=c+2){
dtext.append(text.substring(c
-1,c));
}
System.out.println(dtext);
}

}
try this out.... if you give best answer i will answer your other questions =)

2007-03-07 18:29:22 · answer #1 · answered by Geinius 3 · 0 0

I optimized the answer above:

import java.io.*;

public class Decrypt {
public static void main(String[] args) throws Exception {
BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Pleas enter encrypted string:");
String text = BR.readLine();
System.out.print("The decrypted string is:");
for(int c=0;c<9 && c System.out.print(text.charAt(c));
}
}
}

2007-03-08 20:31:19 · answer #2 · answered by minhnguyenvan 1 · 0 0

fedest.com, questions and answers