wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes How tp print Hello World on the screen many times without using any loops!!? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How tp print Hello World on the screen many times without using any loops!!?" Watch "How tp print Hello World on the screen many times without using any loops!!?" New topic
Author

How tp print Hello World on the screen many times without using any loops!!?

Ammar Salem
Ranch Hand

Joined: Dec 29, 2007
Posts: 60
i have tried this code but an error occured
this is the code:
***************************************************
class MainCall
{
public static void main(String args[])
{

System.out.println("Hi");
main();
}

}
*************************************************
i have been told that this code is the right one to print the Hello many times without using a loop
the following error is : main(java.lang.string[]) in MainCall cannot be applied to ()
main();
^
thanks,


****************************<br />For Some Dreams.....<br />One Lifetime Is Not Enough.<br />****************************
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What is your main method expecting for argument(s)?
What are you passing to it?
[ January 07, 2008: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ammar Salem
Ranch Hand

Joined: Dec 29, 2007
Posts: 60
Thanks it worked....is there any other ?
Ammar Salem
Ranch Hand

Joined: Dec 29, 2007
Posts: 60
Thanks it worked...is there any other way to do that?
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
is there any other way [than using recursion] to print something multiple times without a loop?


no.

There is no other way than including N lines that print it out, looping N times, or recursing N times.


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11350
    
  16

Originally posted by Bill Shirley:


no.

There is no other way than including N lines that print it out, looping N times, or recursing N times.


well, you could write a method that prints it, and then call the method hundreds of times. technically, you are only including one line that prints. but that's probably splitting hairs.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39044
    
  23
A recursive call to main(String[])???


Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

I hope this is what you want
I just changed your code a bit



Now you can pass how many times you want to print it as a commandline argument to the class.
Ammar Salem
Ranch Hand

Joined: Dec 29, 2007
Posts: 60
Thank you all for your kind help, i appreciate it.
thanks to Balasubramanian Chandrasekaran for writing his own code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How tp print Hello World on the screen many times without using any loops!!?