Java Method Recursion In Hindi – Java Recursion In Hindi

Java

Java Recursion In Hindi – Is Post Me Java Method Recursion ke Bare Me Dekhne Wale Hai Ki What is Recursion In Hindi And How Its Works?

Java Recursion In Hindi

Yadi Aapne  HTML Full Course  And CSS Full Course Nhi Read Kiya Hai To Aap Vah Bhi Read Kar Sakte Hai |

What Is Method Recursion in Hindi?

Java Me Recursion Ek Aisi Prikirya Hai Jisme Koi Bhi Method Khud Ko Lagataar Call Karta Hai , Ya Phir Hum Keh Sakte Hain Ki Ek Method Jise Swayam Call Kiya Ja Sakta Hai Use Method Recursion Kehte Hain.

Why We Use It?

Yaha Technique Jatil Problems Ko Saral Problems Mein Todne Ka Tareeka Pradaan Karti Hai, Jinhe Solve Karna Asaan Ho. Method Recursion Humare Code Ko Compact Yani Chota Banata Hai Lekin Samajhne Me Thoda Jatil Bhi Ho Sakta Hai.

How Recursion Works in Hindi?

JAVA Recursive Method

Upar Diye Example Mein Jaisa Ki Hum Dekh Pa Rahe Hain Humne recursive( ) Naam Se Ek Method Define Kiya Hua Hai. Method Ko Do Tareeke Se Call Karke Dikhaya Gya Hai, Ek, Normal Method, Jisme Hum recursive( ) Method Ko main( ) Method Ke Ander Se Call Kr Rhe Hain. Aur Doosra Hai Recursive Method, Jisme recursive( ) Method Apne Aap Ko Hi Apni Method Body Se Call Kr Rha Hai.

What Is Halting Statement In Method Recursion?

To stop the execution of Recursive method, hume method body ke andar kuch conditions dene ki zaroorat hoti hai jo uss execution ko kisi na kisi stage per rok sake, wrna woh recursive method apna execution samapt nhi kar paega aur chalta rhega.

Also Read – Java Arrays

Kisi bhi method ke iss infinite execution ko rokne ke liye hume kuch halting statements ka use karna padta hai. Issliye, hum method ke andar recursive call ko rokne ke liye if…else statement ka use karte hain. Aaiye ek example ki help se hum method recursion aur halting statement ko samajhte hain:

Example

Use Recursion To Add All Of The Numbers Up To 10.

public class MyClass {
  public static void main(String[] args) {
    int result = sum(10);
    System.out.println(result);
  }
  public static int sum(int k) {
    if (k > 0) {
      return k + sum(k - 1);
    } else {
      return 0;
    }
  }
}

Example Explained

Jab sum() Method Ko Call Kiya Jata Hai Toh Method Parameter K Ko K Se Choti Sabhi Values Ke Sum Me Jodta Hai Aur Result Return Karta Hai. Lekin Jab K Ki Value 0 Ho Jaati Hai Toh Method Kewal 0 Return Karta Hai. Running Time Me Program Neeche Di Gayi Process Ko Follow Karta Hai:

10 + sum(9)
10 + ( 9 + sum(8) )
10 + ( 9 + ( 8 + sum(7) ) )

10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + sum(0)
10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + 0

Jaisa ki hum dekh pa rahe hain, method ki body me humne ek halting statement (if…else) ka istemaal kiya hua hai jo har baar check krti hai ki k ki value 0 se jyada hogi toh hi method apne aap ko call kr paega wrna method 0 return krega.

Friends Mujhe Umeed Hai Ki Aapko Method Recursion In Java in Hindi Ke Bare Mai 100% Jankari Ho Gayi Hogi | Agar Aapko Learn Karne Main Dikkat Aa Rahi Hai To Aap Mere Se Contact Kar Sakte Hai |

Leave a Reply

Your email address will not be published. Required fields are marked *