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:
  
  
  
  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"



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();
    }
}
For the sake of efficiency, I suggest you use a StringBuilder. The problem here is that String.replace will have to copy a this string applying the character replacement several times. With a StringBuilder you can apply those character replacements in a single pass over the input string. I had this in mind:

public static String to13375p34k(String word) {
    StringBuilder sb = new StringBuilder(word);

    for (int i = 0; i &lt; sb.length(); ++i) {
        char currentCharacter = sb.charAt(i);

        switch (currentCharacter) {
            case 'o':
                sb.setCharAt(i, '0');
                break;

            case 'l':
                sb.setCharAt(i, '1');
                break;

            case 'e':
                sb.setCharAt(i, '3');
                break;

            case 'a':
                sb.setCharAt(i, '4');
                break;

            case 't':
                sb.setCharAt(i, '7');
                break;
        }
    }

    if (sb.charAt(sb.length() - 1) == 's') {
        sb.setCharAt(sb.length() - 1, 'Z');
    }

    return sb.toString();
}