File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programming Diversions and the fly likes challenging puzzle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "challenging puzzle" Watch "challenging puzzle" New topic

challenging puzzle

monis raza
Ranch Hand

Joined: Sep 05, 2011
Posts: 38

for challenging puzzles visit
Myke Enriq
Ranch Hand

Joined: Feb 13, 2012
Posts: 115
Here is a puzzle form his blog:

cOoKiEs PuZzLe
If cookies were Strings, could you write the Cookie Monster? The class Count is given:

package count;

import monster.CookieMonster;

public class Count {
public static void main(String[] args) {
String noCookie ="cookie");
if (noCookie.isEmpty() && < noCookie.length()) {
// The goal is to reach this line
System.out.println("Minus one cookie!");
Edit the Cookie Monster to make it work:

package monster;

public class CookieMonster {
public static String eat(String cookie) {
return cookie.substring(0, cookie.length() - 6);


Spring AOP and custom class loaders seem like cheating to me. I wonder how you can do this with Java SE only.
I agree. Here's the link:
subject: challenging puzzle
jQuery in Action, 3rd edition