Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Main(String [] args)

 
Ray Dawson
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say I have a code with main(String[]args) and I want a recursive function, then how should I go about it ?

Like without String[]args, here's what I do



It goes on infitenely calling main over & over again.

So I want to do this while having String[]args as parameters in the main().

How do I do this ?
 
Zandis Murāns
Ranch Hand
Posts: 174
Java Java ME Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like this:
 
Tim Moores
Bartender
Posts: 2730
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or just "main(args)". That's an example of "direct recursion".

If you have two methods that call one another -like in your example-, that's called "indirect recursion".
 
Ray Dawson
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zandis Murāns wrote:Like this:


It worked :jumpingjoy:
 
Campbell Ritchie
Sheriff
Posts: 48645
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And don't try mixing static and instance methods like that. The compiler won't like it.
 
Ray Dawson
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:And don't try mixing static and instance methods like that. The compiler won't like it.


Yeah that's one thing which I did try to avoid.

In my main program, I have about 5000 lines of code, with say about 30 functions. All are static & all variables are public & static.
I'm working on multiple threads right now, so you think having public static everywhere can make them thread-unsafe ?
 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ray Dawson wrote:
Campbell Ritchie wrote:And don't try mixing static and instance methods like that. The compiler won't like it.


Yeah that's one thing which I did try to avoid.

In my main program, I have about 5000 lines of code, with say about 30 functions. All are static & all variables are public & static.
I'm working on multiple threads right now, so you think having public static everywhere can make them thread-unsafe ?


Then you should step away from the keyboard and go find yourself another language... ;)

You are not really doing it in an object oriented way. Normally, I allow main-containing classes to be about 3-14 lines. The rest should be taken care of by other instances of other classes.
 
Campbell Ritchie
Sheriff
Posts: 48645
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ove Lindström wrote: . . . find yourself another language... . . . .
If you are doing functional programming, there are several suitable languages, eg Oz, Prolog, LISP, ML. But not Java™.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic