Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

challenging tricky program ... need help

Thread view: 
Mr.Disguise - 05 Nov 2007 09:42 GMT
look at the code below n plz help be solve the trick ...

class testTrick{

public static void main(String args[]){

}

static marker(){

System.out.print("programe executed");

}

}

result required from this programme is that the programme should print
"programme executed", meaning that marker method should be executed.
but there r some rules
1. nothing should be written in both the methods.
2. no other class can be added to the programe.
3. the programe must execute the output statment in the marker method.

its been a month n i am unable to solve the problem plz som1 help me.
am unable to solve this problem because am not a java progammer. i
have searched everything on internet to get a clue but i failed. plz
some1 help me run this programme by strickly following the rules.

thanks
Andrew Thompson - 05 Nov 2007 09:56 GMT
...
>..there r some rules

This is usenet, there are no rules.

OTOH, there is a lot of advice like.  
"Spell words fully, to get more respect."
And many exhortations, such as
"Do your own homework"..

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Roedy Green - 06 Nov 2007 04:15 GMT
>"Do your own homework"..

That looks like puzzle someone posted. Not homework, at least I hope
not.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Gordon Beaton - 05 Nov 2007 10:02 GMT
> look at the code below n plz help be solve the trick ...
[...]
> its been a month n i am unable to solve the problem plz som1 help me.

Y du u n33d 2 s0lv t prb n what d1d u alr3ady try? The z7wsv r ï JLS
q45wdx bz s3kshn 8.7 sg##fp stat1c 1n1t1@71z3r àåäá zoekresultaten.

HTH!

/gordon

--
lyallex - 05 Nov 2007 10:28 GMT
>> look at the code below n plz help be solve the trick ...
> [...]
[quoted text clipped - 8 lines]
>
> --

Exellent reply, very funny indeed ...

A clue for the OP perhaps:

The rules do not preclude the removal of existing code.
Patricia Shanahan - 05 Nov 2007 11:04 GMT
>>> look at the code below n plz help be solve the trick ...
>> [...]
[quoted text clipped - 12 lines]
>
> The rules do not preclude the removal of existing code.

But the problem can be solved, using the technique suggested by Gordon,
without removing any existing code, by the addition of a single line
outside any method. It is also necessary to add "void" to the marker
declaration to make it a syntactically correct method declaration.

The solution I suspect you are thinking of would break rule 3: "3. the
programe must execute the output statment in the marker method."

Patricia
lyallex - 05 Nov 2007 11:18 GMT
>>>> look at the code below n plz help be solve the trick ...
>>> [...]
[quoted text clipped - 22 lines]
>
> Patricia

You are right of course.
Mike  Schilling - 05 Nov 2007 23:53 GMT
>>>> look at the code below n plz help be solve the trick ...
>>> [...]
[quoted text clipped - 20 lines]
> The solution I suspect you are thinking of would break rule 3: "3. the
> programe must execute the output statment in the marker method."

It depends how you read it: does it mean

   must execute the output statement that's currently in the marker method

or

   must execute an output statement as part of the marker method

I think llyalex's solution is clever and arguably withn the rules.  The one
I thought of is the same as Patricia's.
lyallex - 06 Nov 2007 09:26 GMT
Mike Schilling wrote:
>>>>> look at the code below n plz help be solve the trick ...
>>>> [...]
[quoted text clipped - 29 lines]
> I think llyalex's solution is clever and arguably withn the rules.  The one
> I thought of is the same as Patricia's.

As I understand the reply, the 'technique suggested by Gordon' was to
use a static initializer as described in the JLS section 8.7, that is
what I suggested.

3. the programe must execute the output statment in the marker method.

nowhere does it say 'the program must execute the marker method'...

However I think the person marking the homework (?) would probably agree
that this was a refactoring too far and mark me down. I believe however
that is is generally better to remove code if possible rather than
adding more. It usually makes things simpler to understand and reduces
the possibility of unexpected behaviour. I suppose I'm trying to defend
my position now.

Actually, IMHO initialisation should occur when the class is loaded, it
doesn't really make sense to me to put initialisation code in a method
that is visible to sub classes. It will be executed when it makes sense,
on loading, not when the sub class decides it's time.

Anyway, all this is just my opinion of course.
Lew - 06 Nov 2007 14:30 GMT
> 3. the programe must execute the output statment in the marker method.
>
> nowhere does it say 'the program must execute the marker method'...

That is ambiguous.  The phrase "in the marker method" could apply to
"statement" or "execute" in that sentence; it's not clear which.

Signature

Lew

Patricia Shanahan - 06 Nov 2007 14:37 GMT
>> 3. the programe must execute the output statment in the marker method.
>>
>> nowhere does it say 'the program must execute the marker method'...
>
> That is ambiguous.  The phrase "in the marker method" could apply to
> "statement" or "execute" in that sentence; it's not clear which.

Solution A inarguably meets all the requirements. Solution B may meet
all the requirements, depending on exactly how they are interpreted.

I would go with A unless B has sufficient advantage to justify going
back to whoever set the requirements for clarification. Why be clever
when you can be right?

Patricia
Mike  Schilling - 06 Nov 2007 17:27 GMT
>>> 3. the programe must execute the output statment in the marker method.
>>>
[quoted text clipped - 9 lines]
> back to whoever set the requirements for clarification. Why be clever
> when you can be right?

Because it's fun?

"Don't try to be too clever" is a good general rule or programming, but this
is a puzzle with deliberately artifical rules.
Mr.Disguise - 12 Nov 2007 19:21 GMT
hi there,
thanks for giving me so many titles. now can i say something as am the
guy that actually posted the question.

the rules r fixed,

nothing to write in methods,
no addition of any new class,
programe must execute the output statement.

i have the solution,
all the thanks goes to u guys. u were very helpful.

well i am a newbie to java ofcourse. but in real am a c# programmer. i
havnt evn thought about any java programe in the past 8 years.
before i leave i will mention that the guy at the top really spent
some good efforts on that "n33d s0lv" msg. n it did gifted me a
smile.
thanks buddy. programmers r normally boring ppl, but i think u do hav
a sense of humor. but plz now dont reply to this msg wid that morse
code again, coz its really hard to decript.
anyways thanks for the help to all u guys.
bye.
Gordon Beaton - 05 Nov 2007 11:26 GMT
> The rules do not preclude the removal of existing code.

I don't expect anyone to be able to read my reply without already
understanding the solution I was implying, but you don't need to
remove anything and I wasn't implying that you do. Just invoke the
existing method in an appropriate manner (assuming the addition of the
missing keyword, as Patricia already pointed out).

/gordon

--
lyallex - 05 Nov 2007 11:50 GMT
>> The rules do not preclude the removal of existing code.
>
[quoted text clipped - 7 lines]
>
> --
Yes, I understand, I'm always trying to reduce the amount of code in my
classes and yes I agree that this was a reduction too far. I forgot how
careful you have to be when replying to this group ... Sorry, it won't
happen again :-( (suitably chastised).
Lew - 05 Nov 2007 14:46 GMT
>> look at the code below n plz help be solve the trick ...
> [...]
>> its been a month n i am unable to solve the problem plz som1 help me.
>
> Y du u n33d 2 s0lv t prb n what d1d u alr3ady try? The z7wsv r ï JLS
> q45wdx bz s3kshn 8.7 sg##fp stat1c 1n1t1@71z3r àåäá zoekresultaten.

Be careful that you aren't hazing a newbie!

Signature

Lew

Gordon Beaton - 05 Nov 2007 14:44 GMT
>>> look at the code below n plz help be solve the trick ...
>> [...]
[quoted text clipped - 4 lines]
>
> Be careful that you aren't hazing a newbie!

Just avoiding giving away h0m3w0rk s0lut10nz...

/gordon

--
Lew - 05 Nov 2007 15:14 GMT
>>> Y du u n33d 2 s0lv t prb n what d1d u alr3ady try? The z7wsv r ï JLS
>>> q45wdx bz s3kshn 8.7 sg##fp stat1c 1n1t1@71z3r àåäá zoekresultaten.

Lew wrote:
>> Be careful that you aren't hazing a newbie!

> Just avoiding giving away h0m3w0rk s0lut10nz...

I was kidding, of course.  w00t!!!111 lol

Signature

Lew

Roedy Green - 06 Nov 2007 04:17 GMT
>Be careful that you aren't hazing a newbie!

He did not insult the newbie.  He simply mirrored him, so that if all
goes well the point gently dawns on the newbie, in a way that makes
him too smile.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Andrew Thompson - 06 Nov 2007 06:09 GMT
>>Be careful that you aren't hazing a newbie!
>
>He did not insult the newbie.  He simply mirrored him, so that if all
>goes well the point gently dawns on the newbie, in a way that makes
>him too smile.

It made me laugh*, though I cannot see how it could have
done anything good for the OP unless the the OP understood
the reply.  * The funny aspect being that they obviously would
not.

If they *did* understand that answer,
[ a) They probably would not have had to ask in the first
case. ]
b) Assuming they still did ask, and got that answer, they
would probably guess the replier was 'more l33t than them' -
never taking it for the 'dripping with sarcasm' reply that it
was..

Holding a mirror up to an idiot produces a gawping idiot,
not an 'enlightened soul'.

Signature

Andrew Thompson
http://www.athompson.info/andrew/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.