Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ammar Salem
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your main method expecting for argument(s)?
What are you passing to it?
[ January 07, 2008: Message edited by: Ben Souther ]
 
Ammar Salem
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks it worked....is there any other ?
 
Ammar Salem
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks it worked...is there any other way to do that?
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12086
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Posts: 48418
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A recursive call to main(String[])???


 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your kind help, i appreciate it.
thanks to Balasubramanian Chandrasekaran for writing his own code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic