Page 135 - ComputerScience_Class_11
P. 135
Scanner sc = new Scanner(System.in);
Circle c = new Circle();
System.out.print("Enter the radius of the circle: ");
c.radius = sc.nextDouble();
c.calculateCircumference();
c.display();
sc.close();
}
}
3. import java.util.Scanner;
class Rectangle {
double length, breadth, diagonal;
void calculateDiagonal() {
diagonal = Math.sqrt((length * length) + (breadth * breadth));
}
void display() {
System.out.println("Length: " + length);
System.out.println("Breadth: " + breadth);
System.out.println("Diagonal of the rectangle: " + diagonal);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Rectangle r = new Rectangle();
System.out.print("Enter the length of the rectangle: ");
r.length = sc.nextDouble();
System.out.print("Enter the breadth of the rectangle: ");
r.breadth = sc.nextDouble();
r.calculateDiagonal();
r.display();
sc.close();
}
}
Objects 133

