samedi 3 décembre 2016

How to print a pattern 16 11 6 1 -4 1 6 11 16 using recursion in java?

class Rec
{
    public int pattern(int n)
    {
        if(n>=-4)
        return pattern(n-5);
        else
        return pattern(n+4);
    }
    public static void main(String args[])
    {
        int a=16;
        Rec ob=new Rec();
        System.out.print("16\t"+ob.pattern(a));
    }   
}

Above is my code which compiles successfully but doesn't give any output.

Aucun commentaire:

Enregistrer un commentaire