Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Recursive methods in Java

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to use the recursive method in Java, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Recursion

The phenomenon that the method definition itself invokes the method itself is called recursion

What we learned before that: for example, StringBuffer.append (). Append (). Append () this is not called recursion. This successive call to a method called Math.max (Math.max (aline b), c) is not recursive either, so what are these? These are method calls.

So what is recursion?

For example:

Once upon a time there was a mountain, there was a temple in the mountain, there was an old monk in the temple, the old monk was telling a story to the young monk, the story was:.

Once upon a time there was a mountain, there was a temple in the mountain, there was an old monk in the temple, the old monk was telling a story to the young monk, the story was:.

Once upon a time there was a mountain, there was a temple in the mountain, there was an old monk in the temple, the old monk was telling a story to the young monk, the story was:.

Once upon a time there was a mountain, there was a temple in the mountain, there was an old monk in the temple, the old monk was telling a story to the young monk, the story was:.

. . The temple is gone, recursion is over.

For example:

Study-high-tech employment-take a wife-have a baby-study-high-paid employment-marry a wife-give birth to a child-study-high-paid employment-marry a wife-have a baby-study-study-high-tech employment-marry a wife-have a baby-study-high-paid employment-marry a wife-have a baby-study-high-tech employment-marry a wife-have a baby-study-study-get a wife-have a baby-have a baby- Study-high-tech employment-get a wife-give birth to a baby-study-high-paying employment-get a wife-have a baby

Can't get a wife, can't have a baby, recursion ends.

Recursive considerations:

Recursion must have an exit and end condition, otherwise the number of recursion in the dead loop should not be too much, otherwise memory overflow will occur and recursion cannot be used.

Case one

Reference Code:

Public class RecursionDemo1 {public static void main (String [] args) {show (10);} private static void show (int I) {/ / define the end condition if (I)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report