Skip to main content
Code Review

Return to Question

added 2 characters in body
Source Link
Mast
  • 13.8k
  • 12
  • 56
  • 127

Write a method leetSpeak that accepts two parameters: a Scanner representing an input file, and a PrintStream representing an output file. Your method should convert the input file's text to "leet speak" (aka 1337 speak), an internet dialect where various letters are replaced by other letters/numbers. Output the leet version of the text to the given output file. Preserve the original line breaks from the input. Also wrap each word of input in parentheses. Perform the following replacements:

table of characters

For example, if the input file lincoln.txtlincoln.txt contains the following text:

four score and seven years ago our

fathers brought forth on this continent a new nation And your method is called in the following way:

Scanner input = new Scanner(new File("lincoln.txt"));

Scanner input = new Scanner(new File("lincoln.txt"));

PrintStream output = new PrintStream(new File("leet.txt"));

PrintStream output = new PrintStream(new File("leet.txt"));
leetSpeak(input,output);

leetSpeak(input,output);

Then after the call, the output file leet.txt should contain the following text:

(f0ur) (sc0r3) (4nd) (s3v3n) (y34rZ) (4g0) (0ur)

(f0ur) (sc0r3) (4nd) (s3v3n) (y34rZ) (4g0) (0ur)

(f47h3rZ) (br0ugh7) (f0r7h) (0n) (7hiZ) (c0n7in3n7) (4) (n3w) (n47i0n)

(f47h3rZ) (br0ugh7) (f0r7h) (0n) (7hiZ) (c0n7in3n7) (4) (n3w) (n47i0n)

You may assume that each token from the input file is separated by exactly one space.

Hint: You may want to use the String object's replace method, which is used as follows:

String str = "mississippi"; str = str.replace("s", "*"); // str = "miiippi"

String str = "mississippi"; str = str.replace("s", "*"); // str = "mi**i**ippi"

Write a method leetSpeak that accepts two parameters: a Scanner representing an input file, and a PrintStream representing an output file. Your method should convert the input file's text to "leet speak" (aka 1337 speak), an internet dialect where various letters are replaced by other letters/numbers. Output the leet version of the text to the given output file. Preserve the original line breaks from the input. Also wrap each word of input in parentheses. Perform the following replacements:

table of characters

For example, if the input file lincoln.txt contains the following text:

four score and seven years ago our

fathers brought forth on this continent a new nation And your method is called in the following way:

Scanner input = new Scanner(new File("lincoln.txt"));

PrintStream output = new PrintStream(new File("leet.txt"));

leetSpeak(input,output);

Then after the call, the output file leet.txt should contain the following text:

(f0ur) (sc0r3) (4nd) (s3v3n) (y34rZ) (4g0) (0ur)

(f47h3rZ) (br0ugh7) (f0r7h) (0n) (7hiZ) (c0n7in3n7) (4) (n3w) (n47i0n)

You may assume that each token from the input file is separated by exactly one space.

Hint: You may want to use the String object's replace method, which is used as follows:

String str = "mississippi"; str = str.replace("s", "*"); // str = "miiippi"

Write a method leetSpeak that accepts two parameters: a Scanner representing an input file, and a PrintStream representing an output file. Your method should convert the input file's text to "leet speak" (aka 1337 speak), an internet dialect where various letters are replaced by other letters/numbers. Output the leet version of the text to the given output file. Preserve the original line breaks from the input. Also wrap each word of input in parentheses. Perform the following replacements:

table of characters

For example, if the input file lincoln.txt contains the following text:

four score and seven years ago our

fathers brought forth on this continent a new nation And your method is called in the following way:

Scanner input = new Scanner(new File("lincoln.txt"));
PrintStream output = new PrintStream(new File("leet.txt"));
leetSpeak(input,output);

Then after the call, the output file leet.txt should contain the following text:

(f0ur) (sc0r3) (4nd) (s3v3n) (y34rZ) (4g0) (0ur)
(f47h3rZ) (br0ugh7) (f0r7h) (0n) (7hiZ) (c0n7in3n7) (4) (n3w) (n47i0n)

You may assume that each token from the input file is separated by exactly one space.

Hint: You may want to use the String object's replace method, which is used as follows:

String str = "mississippi"; str = str.replace("s", "*"); // str = "mi**i**ippi"
Tweeted twitter.com/StackCodeReview/status/936504598856159233
Source Link
cody.codes
  • 2k
  • 2
  • 26
  • 45

Converting text into l33t speak

Write a method leetSpeak that accepts two parameters: a Scanner representing an input file, and a PrintStream representing an output file. Your method should convert the input file's text to "leet speak" (aka 1337 speak), an internet dialect where various letters are replaced by other letters/numbers. Output the leet version of the text to the given output file. Preserve the original line breaks from the input. Also wrap each word of input in parentheses. Perform the following replacements:

table of characters

For example, if the input file lincoln.txt contains the following text:

four score and seven years ago our

fathers brought forth on this continent a new nation And your method is called in the following way:

Scanner input = new Scanner(new File("lincoln.txt"));

PrintStream output = new PrintStream(new File("leet.txt"));

leetSpeak(input,output);

Then after the call, the output file leet.txt should contain the following text:

(f0ur) (sc0r3) (4nd) (s3v3n) (y34rZ) (4g0) (0ur)

(f47h3rZ) (br0ugh7) (f0r7h) (0n) (7hiZ) (c0n7in3n7) (4) (n3w) (n47i0n)

You may assume that each token from the input file is separated by exactly one space.

Hint: You may want to use the String object's replace method, which is used as follows:

String str = "mississippi"; str = str.replace("s", "*"); // str = "miiippi"

I'm looking for general feedback, and other ways to accomplish the task of solving this problem. My hope is that there will be some interesting feedback on this that I can apply to my future coding. If there are any bugs in my code, please let me know.

public static void leetSpeak (Scanner sc, PrintStream ps) {
  while (sc.hasNextLine()) {
    String line = new String(sc.nextLine());
    Scanner tokenScanner = new Scanner(line);
    while (tokenScanner.hasNext()) {
      String token = new String(tokenScanner.next());
      token = token.replace("o", "0");
      token = token.replace("l", "1");
      token = token.replace("e", "3");    
      token = token.replace("a", "4");
      token = token.replace("t", "7");
      if (token.substring(token.length() - 1).equals("s")) {
          token = new String(token.substring(0, token.length() - 1));
          token += "Z";
      } 
      ps.print("(" + token + ")" + " ");
    }
  ps.println();
  }
}
lang-java

AltStyle によって変換されたページ (->オリジナル) /