File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Meaningless Drivel and the fly likes 100 times Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Meaningless Drivel
Bookmark "100 times "hello world" without loop or recursive " Watch "100 times "hello world" without loop or recursive " New topic
Author

100 times "hello world" without loop or recursive

Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1824

Ugh....Jim, the for loop printed doesn't have any braces delimiting it. I can't understand it


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671


"I'm not back." - Bill Harding, Twister
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
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?


Francis Siu
SCJP, MCDBA
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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

Joined: Jan 04, 2003
Posts: 867
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

Joined: Jan 30, 2002
Posts: 3451
for(int i = 0;i<100;i++)
System.out.println("Hello World");
Busted!


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
sahil kumar garg sangrur
Greenhorn

Joined: Jun 05, 2012
Posts: 16
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

Joined: Mar 05, 2008
Posts: 3018
    
  10
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

Joined: Aug 22, 2010
Posts: 3611
    
  60

What about this:?
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
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

Joined: Aug 22, 2010
Posts: 3611
    
  60

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

Joined: Mar 05, 2008
Posts: 3018
    
  10
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.
 
permaculture playing cards
 
subject: 100 times "hello world" without loop or recursive