• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

challenging puzzle

 
Ranch Hand
Posts: 38
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for challenging puzzles visit
namaste-java.blogspot.com
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 = CookieMonster.eat("cookie");
if (noCookie.isEmpty() && CookieMonster.eat(noCookie).length() < 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic