Short Java Quine.

D

Daniel Pitts

Remove any line-breaks, and this becomes a quine.

enum Q {a("enum Q{a(%c%s%c);Q(String
t){System.out.printf(t,34,t,34);System.exit(0);}}");Q(String
t){System.out.printf(t,34,t,34);System.exit(0);}}


Just thought I'd share.
 
T

Tony Winslow

Daniel said:
Remove any line-breaks, and this becomes a quine.

enum Q {a("enum Q{a(%c%s%c);Q(String
t){System.out.printf(t,34,t,34);System.exit(0);}}");Q(String
t){System.out.printf(t,34,t,34);System.exit(0);}}


Just thought I'd share.
Would you please be more specific?
I can't figure out what you mean!
Thank you!
 
D

Daniel Pitts

Tony said:
Would you please be more specific?
I can't figure out what you mean!
Thank you!
A quine is a program who's output is its own source code.

If you compile Q.java and then run java Q, it will output itself. All
this without reading from the original source file, mind you.
 
A

Andrea Francia

Daniel said:
Remove any line-breaks, and this becomes a quine.

enum Q {a("enum Q{a(%c%s%c);Q(String
t){System.out.printf(t,34,t,34);System.exit(0);}}");Q(String
t){System.out.printf(t,34,t,34);System.exit(0);}}


Just thought I'd share.
I'm not able to get this Quine works. It lacks of the 'main' method.
 
W

Wildemar Wildenburger

Andrea said:
I'm not able to get this Quine works. It lacks of the 'main' method.
Doesn't need one. Compiling it creates a Q.class file, wich can be run
by "java Q".

/W
 
A

Andrea Francia

Wildemar said:
Doesn't need one. Compiling it creates a Q.class file, wich can be run
by "java Q".

It's a news for me, but it's true:
With

class A {
static {
System.out.println("Hello world!");
}
}

I obtain:

$ java A
Hello world!
Exception in thread "main" java.lang.NoSuchMethodError: main

And with

class B {
static {
System.out.println("Hello world!");
System.exit(0);
}
}

I obtain:

$ java B
Hello world!

Now is clear to me that the JVM before load the class and then try to
execute the 'main' method. And now this seems obvious.
 
T

Tony Winslow

T

Tony Winslow

Daniel said:
Remove any line-breaks, and this becomes a quine.

enum Q {a("enum Q{a(%c%s%c);Q(String
t){System.out.printf(t,34,t,34);System.exit(0);}}");Q(String
t){System.out.printf(t,34,t,34);System.exit(0);}}


Just thought I'd share.
It works!
Could you please explain the `enum' syntax to me briefly?
Thank you!
 
C

Christian

Tony said:
As I'm in mainland China now, I can't visit wiki.
Do you know any solutions to this problem?

VPN tunnel to your own Server?
Run your own Proxy at home or get some proxy service?
SSH to your homepc and use lynx to look at wikipedia?

possibilities seem endless..
 
D

Daniele Futtorovic

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top