NPTEL Programming in Java Week3 Assignment-3 Solutions 2021 | Swayam

 



Week-1

Ans of Question - 1

if(n==1)
    return 0;
else if(n==2)
    return 1;
return fib(n-1) + fib(n-2)
        
Ans of Question - 2

class point 
{
    double x;
    double y;
     
    void distance(Point p1, Point p2)
    {
        double dis=Math.sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
        System.out.print(dis);
    }
}

Ans of Question - 3
double height;
Test1(double length ,double h)
{
    super(length);
    height=h;
}
Test1(double length ,double breadth,double h)
{
    super(length,breadth);
    height=h;
}
double calculate()
{
    return length*breadth*height;
}


Ans of Question - 4
QuestionScope obj=new QuestionScope();
System.out.println(obj.sum(n1,n2));
System.out.println(QuestionScope.multiply(n1,n2));

Ans of Question - 5
static void swap(Question t)
{
    int obj;
    obj=t.e1;
    t.e1=t.e2;
    t.e2=obj;
}

No comments:

Powered by Blogger.