Computer Science, asked by IBoss, 1 year ago

ICSE Class 10 computer science question

answer fast

functions and methods

NO SPAMMING​

Attachments:

Answers

Answered by Anonymous
6

\mathbb{\underline{CODE}}

import java.util.*;

class Rectangle  

{

int length ;

int breadth ;

void inputdata()

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter the length , breadth");

length =sc.nextInt();

breadth=sc.nextInt();

calculate();

}

void calculate()

{

int area=length*breadth;

double diagonal=Math.sqrt(length*length+breadth*breadth);

int perimeter=2*(length+breadth);

outputdata(area,diagonal,perimeter);

}

void outputdata(int area,double diagonal,int perimeter)

{

System.out.println("Area="+area);

System.out.println("Perimeter="+perimeter);

System.out.println("Diagonal="+diagonal);

}

}

\mathcal{\underline{EXPLANATION}}

↪ The above code is an example of functions .

↪ Note that it is not mentioned in the question but we have to pass the values of area , diagonal and perimeter to the last function .

↪ The formula for diagonal = √( length² + breadth² )

↪ We could have also written the power as Math.pow(length,2) .

↪ The function Math.pow is always in double .

↪ Also the function Math.sqrt is in double .


IBoss: Thanks man...
Similar questions