Help with a Java program for my class? I'm stumped!

Status
Not open for further replies.

ShangTi911

Ars Tribunus Militum
1,599
Okay, here's the deal. This is a program my CS prof gave so that he would have a way to determine who would deserve to be rounded up to the next grade point in the event that they're borderline. (i.e. 89.5 to a 90) I've been digging through my textbook and some reference books, but I'm stumped on this one. If any of you could give me an idea on where to look to figure this one out, I'd really appreciate it. I'm not looking for someone to write the program for me, just someone to point me in the right direction as to how to get started.

Anyway, here's the problem. We have to write a java program that outputs itself as text to the screen. Line for line, an exact copy, down to the indentation. The catch is that we can't read from the file. Anybody got any ideas? I'd really appreciate any help.
 

j3

Ars Tribunus Militum
2,226
Can you elaborate on the restriction of "can't read from the file." It seems you have to "read" from the file (in one form or another) to do it. I mean, any kind of trickery with the bytecode (some kind or redirection or something) isn't going to print anything near the original source code. The only possible routes I can see are some kind of "reading" a source file or actually having the text embedded in the source (which seems to be recursivly impossible).

I guess I am stumped too :p
Good question.

-j3
 
It is called a 'quine'. Here is a sample in c++ that someone else wrote. You have to insure that the code is on one line or else it won't work. use g++ to compile.

extern "C" int printf(char *, ...); extern "C" int putchar(int); int main() { char *p = "extern %cC%c int printf(char *, ...); extern %cC%c int putchar (int); int main() { char *p = %c%s%c; int q = '%c'; int r = '%c%c'; printf(p, q, q, q, q, p, q, q, r, r, r); putchar('%cn'); }"; int q = '"'; int r = '\\'; printf(p, q
, q, q, q, q, p, q, q, r, r, r); putchar('\n'); }
 
Status
Not open for further replies.