All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
print 'print 'print 'print ... (Posted on 2003-09-19) Difficulty: 5 of 5
Write a program that prints itself.

See The Solution Submitted by DJ    
Rating: 4.6875 (16 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Self Printing Program in Java | Comment 25 of 32 |
This is the same idea as my BASIC program. Half of the program is data echoing the other half.

public class selfprint { public static void main(string[] args) {
String[] data = new String[13];
char quote=34, endline=';';
String front = Character.toString('d')+'a'+'t'+'a'+'[';
String middle = Character.toString(']')+'='+quote;
String back = Character.toString(quote)+endline;
data[0]="public class selfprint { public static void main(string[] args) {";
data[1]="String[] data = new String[13];";
data[2]="char quote=34, endline=';';";
data[3]="String front = Character.toString('d')+'a'+'t'+'a'+'[';";
data[4]="String middle = Character.toString(']')+'='+quote;";
data[5]="String back = Character.toString(quote)+endline;";
data[6]="for (int i = 0; i<26; i++) {\";
data[7]=\"if (i<7) {\";
data[8]=\"System.out.println(data[i]);\";
data[9]=\"} else if (i>20) {";
data[10]="System.out.println(data[i-14]);";
data[11]="} else {";
data[12]="System.out.println(front+(i-7)+middle+data[i-7]+back);";
data[13]="} } } }";
for (int i = 0; i<28; i++) {
if (i<7) {
System.out.println(data[i]);
} else if (i>20) {
System.out.println(data[i-14]);
} else {
System.out.println(front+(i-7)+middle+data[i-7]+back);
} } } }
  Posted by Brian Smith on 2003-09-24 14:19:11
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (1)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (9)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information