next up previous
Next: The do loop Up: Unit 06 Previous: Example of for loop:

Example of for loop: ``cracking'' an encoded string

Suppose a public static method decode() is available, which decodes a string encoded with the encode() method we have seen before. Write a public static method that takes as parameters an already encoded string str and the minimum and maximum codes (respectively min and max) that could have been used for encoding str, and prints all strings obtained from str by decoding it with all values between min and max.

public static void crack(String str, int min, int max) {
  for (int i = min; i <= max; i++)
    System.out.println(decode(str, i));


next up previous
Next: The do loop Up: Unit 06 Previous: Example of for loop: