NPTEL Programming in Java Week5 Assignment-5 Solutions 2021 | Swayam

 



Zebronics Zeb-Transformer-k USB Gaming Keyboard with Multicolor LED Effect

Rating - 4.5 to 4.8

Price - 1000₹ to 1100₹

8000 People already Purchase

for latest information click - https://amzn.to/3rWtdNz





Question5_1

class A implements Number{

    int i,square;

    public int findSqr(int i){

        square=i*i;

        return square;

    }

}


Question5_2

class B implements GCD{

    int n1,n2;

    public int findGCD(int n1,int n2)

    {

        if(n1==0 && n2==0)

            return -1;

        else if(n2==0)

            return n1;

        else 

            return findGCD(n1,n1%n2);

    }

}


Question5_3

int result;

a=input.nextInt();

b=input.nextInt();

try

{   

    result=a/b;

    System.out.println(result);

}

catch(ArithmeticException e)

{

    System.out.println("Exception caught: Division by zero.");

}


Question5_4

try

{   

    for(int i=0;i<length;i++)

        name[i]=sc.nextInt();

        for(int i=0;i<length;i++)

        {sum=sum+name[i];}

       System.out.print(sum);

}

catch(InputMismatchException e)

{

    System.out.println("You entered bad data. ");

}


Question5_5

try

    {

        switch (i)

        {

case 0 :

            int zero = 0; 

            j = 92/ zero; 

            break;

        case 1 : 

            int b[ ] = null; 

            j = b[0] ; 

            break;

      default:

    System.out.println("No exception");

}

    }catch(Exception e){System.out.print(e);}

No comments:

Powered by Blogger.