Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static int gcd(double a, int b) {
- int gcd = 1;
- int k = 2;
- while (k <= a && k <= b) {
- if (a % k == 0 && b % k == 0) {
- gcd = k;
- }
- k++;
- }
- return gcd;
- }
- public static String oddoreven(int a) {
- return (a % 2 == 0 ? "EVEN" : "ODD");
- }
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.println("Enter Raidus for circle: ");
- double raidus = scan.nextDouble();
- Circle cir = new Circle(raidus);
- double cirarea = cir.getArea();
- System.out.println("The Area of circle is:" + cirarea);
- System.out.println("Enter height and width for the rectanguler: ");
- System.out.print("height -> ");
- int h = scan.nextInt();
- System.out.print("width -> ");
- int w = scan.nextInt();
- Rectangule rect = new Rectangule(h, w);
- int rectarea = rect.getArea();
- System.out.println("The Area of rectangule is:" + rectarea);
- int gcd = gcd(cirarea, rectarea);
- System.out.println("the gcd is: " + gcd);
- System.out.println("the gcd is: " + oddoreven(rectarea));
- scan.close();
- }
- }
- class Circle {
- private double redus;
- Circle() {
- redus = 1.0;
- }
- Circle(double newr) {
- redus = newr;
- }
- double getArea() {
- return redus * redus * Math.PI;
- }
- double getArea(double r) {
- return r * r * Math.PI;
- }
- }
- class Rectangule {
- private int h;
- private int w;
- Rectangule() {
- h = 1;
- w = 1;
- }
- Rectangule(int a, int b) {
- h = a;
- w = b;
- }
- int getArea() {
- return h * w;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement