Intermediate Java Tutorial – 3 – Recursion

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

31 responses to “Intermediate Java Tutorial – 3 – Recursion”

  1. Jonah Cornish Avatar

    Damn man, you explain everything so well and always fill in the questions I am thinking as I watch. Great vids!

  2. Adeline Shen Avatar

    Brilliant, great explanation.

  3. wenhao dong Avatar

    this is just  f(n)=n*f(n-1)

  4. Jake Round Avatar

    why didn't we use recursion in 1st method?

  5. Mrmagical Rabbit Avatar

    yeah problem solved when you find the only "1"

  6. Yegor S. Abramenkov Avatar

    This is just great, thanks a lot man! This is literally the best and easiest explanation of stuff that people are cracking their heads on all over again with books that are explaining it in a far for dissicult manner.

  7. JWIgnatius Avatar

    Great tutorial man, helped the lightbulb in my head finalllyyy spark. Very interesting concept, and very well explained by you. Have a good day!

  8. Mark Rayne Avatar

    when I first looked at this video years ago when I was a beginner it was great made sense and explained it in details but looking back now with having more programming experience it was good to a certain point but this really is just a BASIC example of recursion,he could of explained it much better like how the return in each stack frame(activation record) works and how it interacts with the calling frame,so yeah very basic video this barely scratches the surface of recursion,if you want to really get a better understanding of recursion read books,forums and also there is much better videos on youtube if you look hard enough explaining recursion and how it works in detail.

  9. Kaushal pant Avatar

    if I'm calculating the value of fact(200) output is zero..
    even after using long(32bit)
    little help plz

  10. Kaushal pant Avatar

    if we use int we get the same value. why are we using long?

  11. Black Ara Avatar

    what kind of system could i make using recursion method? answer me please

  12. Prabhakar Kevat Avatar

    We can also,

    public static int factorial(int num){
    if(num <= 1) return 1;
    return num * factorial(num-1);
    }

    if the number is <=1 following code will not be executed as the return statement breaks out of the function.

  13. mess ssy Avatar

    i wish you can explain to me how you know so much. were you born with this, like i am serious any suggestions with books to read ?

  14. Matthew Alaa Avatar

    you are the best, bucky!

  15. Mayouf Med Avatar

    why not this !!

    public class hallo {

    //main
    public static void main(String [] args){
    //Common
    Scanner input = new Scanner (System.in);
    System.out.println("enter you x");
    int x;
    x = input.nextInt();
    factorial(x);
    }
    //x!
    public static void factorial(int x){
    int sum = 1;
    for(int i=1;i<=x;i++){
    sum*=i;
    }
    System.out.print(x+"! = "+sum);
    }
    }

  16. barnesdouglass Avatar

    God bless you. University professors are absolutely useless

  17. Olivia Shettles Avatar

    You give the best explanations! Thank you so much for this video.

  18. Eder Santos Avatar

    Great Video!!!! Bucky you Rock!!!

  19. a aa Avatar

    good explanation for an absolute beginner

  20. Christiana Julia Avatar

    2009 video is on sleek!

    here is my reformated code

    thanks Bukky

    import java.util.Scanner;

    /**
    *
    * @author Christy
    */
    public class Recursivity {

    public static void main(String[] args) {

    Scanner input = new Scanner(System.in);
    System.out.println("Please input an integer to get a factoriel : ");
    int num = input.nextInt();

    System.out.println("Factoriel of " + num + " is : " + fact(num));

    }

    public static long fact(long n){
    // since 0 or 1 dfactorial the answer is alsways 0

    // So if you enter a number less than 1, return value to 1

    if(n <=1)
    return 1;
    // Else return the value of n in the method time the
    // factorial. Which is number minus 1
    else
    return n* fact(n-1);

    }

    }

  21. Yogi915 Avatar

    Thank you Bucky! I viewed like 10 videos and couldn't figure it out. Your example at end made it finally click!

  22. Luke Perez Avatar

    what if instead of "fact(n-1)" on line 14, it was "fact(n+1)"? Would it b an infinite loop?

  23. Aman Ladia Avatar

    Thanks a lot! Your tutorials are simply awesome

  24. Joel G. Rodriguez Avatar

    Just read a whole chapter on Recursion from my course textbook and still could not grasp this. 8 minutes and you made this click.

  25. The Fox army Avatar

    In this example, couldn't we just use a for loop?

  26. Osama Habib Avatar

    what ide is he using?

  27. Janani Sabapathy Avatar

    Hi Bucky,
    How can I store the result in a variable before returning it.If I try storing it in a variable, it shows 1 as the answer

  28. Isabel M. Avatar

    thank you so so much. i understood this better then my 1h class at school

Leave a Reply

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