ICSE Class 10 computer science question
answer fast
functions and methods
NO SPAMMING
Answers
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);
}
}
↪ 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 .