• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

100 times "hello world" without loop or recursive

 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ugh....Jim, the for loop printed doesn't have any braces delimiting it. I can't understand it
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Michael and Jim
oo...
I regret that I can not see the elegant coding result.
JAD refuses to work with .class files whose version number exceeds 46 (meaning, no JDK 1.3 or 1.4).
The compiler give me following error message
java.lang.UnsupportedClassVersionError: HeresYourLoop
( Unsupported major.minor version 48.0 )
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
at java.lang.ClassLoader.defineClass(ClassLoader.java:426)
at test2.FoundTheLoopHelloWorld100.<init>(FoundTheLoopHelloWorld100.java:9)
at test2.FoundTheLoopHelloWorld100.main(FoundTheLoopHelloWorld100.java:9)
Exception in thread "main"
I really want to see the result
How can I do?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Michael's code, the 8th number (index 7) in the array "bytes" is 48. Change it to 46 (using a text editor). Write these bytes to a file and decompile. The same technique will probably work in my code.
[ May 13, 2003: Message edited by: Jim Yingst ]
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Jim
I see the elegant hided coding

Does the CIA use the same technique to decrypt the encrypted message from Russia?
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for(int i = 0;i<100;i++)
System.out.println("Hello World");
Busted!
 
sahil kumar garg sangrur
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have some idea for this if you want to print "hello world" 100 times without using the loop,recursion and any control structure see this solution
class a
{
static int i=0;
int a[]=new int[101];
a()
{
i++;
a[i]=i;
System.out.println("hello world");
new b();
}
}

class b extends a
{
b()
{
}
public static void main(String ff[])
{
new b();
}
}
 
Mike Simmons
Ranch Hand
Posts: 3040
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Clearly recursive. Constructor b() calls a() which calls b(). See discussion of 2-phase recursion on the previous page. Nothing new here.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about this:?
 
Mike Simmons
Ranch Hand
Posts: 3040
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For that Martin, there's a loop cleverly hidden in the toString() method, implemented in AbstractCollection. And more in replace() and replaceAll().
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it is. Unfortunately, the original assignment text is no longer available, but from the discussion I've understood that neither loops, nor stuffing the "hello world" 100 times into the program are allowed. So the only thing that is left is some sort of a self-modifying assembly code, since I'm pretty sure that you cannot even print in Java without invoking some loops buried deep in the IO system
 
Mike Simmons
Ranch Hand
Posts: 3040
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, all the "solutions" thus far have been exercises in how to hide a loop somewhere. Or how to hide recursion somewhere. I don't think there is any truly satisfactory solution, but it's interesting to see what tricks people came up with.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic