Advertisement
Osan_Salah

Untitled

Jan 30th, 2024
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Main {
  4.     public static int gcd(double a, int b) {
  5.         int gcd = 1;
  6.         int k = 2;
  7.         while (k <= a && k <= b) {
  8.             if (a % k == 0 && b % k == 0) {
  9.                 gcd = k;
  10.             }
  11.             k++;
  12.         }
  13.         return gcd;
  14.     }
  15.  
  16.     public static String oddoreven(int a) {
  17.         return (a % 2 == 0 ? "EVEN" : "ODD");
  18.     }
  19.  
  20.     public static void main(String[] args) {
  21.         Scanner scan = new Scanner(System.in);
  22.  
  23.         System.out.println("Enter Raidus for circle: ");
  24.         double raidus = scan.nextDouble();
  25.         Circle cir = new Circle(raidus);
  26.         double cirarea = cir.getArea();
  27.         System.out.println("The Area of circle is:" + cirarea);
  28.  
  29.         System.out.println("Enter height and width for the rectanguler: ");
  30.         System.out.print("height -> ");
  31.         int h = scan.nextInt();
  32.         System.out.print("width -> ");
  33.         int w = scan.nextInt();
  34.         Rectangule rect = new Rectangule(h, w);
  35.         int rectarea = rect.getArea();
  36.         System.out.println("The Area of rectangule is:" + rectarea);
  37.  
  38.         int gcd = gcd(cirarea, rectarea);
  39.         System.out.println("the gcd is: " + gcd);
  40.  
  41.         System.out.println("the gcd is: " + oddoreven(rectarea));
  42.         scan.close();
  43.     }
  44. }
  45.  
  46. class Circle {
  47.     private double redus;
  48.  
  49.     Circle() {
  50.         redus = 1.0;
  51.     }
  52.  
  53.     Circle(double newr) {
  54.         redus = newr;
  55.     }
  56.  
  57.     double getArea() {
  58.         return redus * redus * Math.PI;
  59.     }
  60.  
  61.     double getArea(double r) {
  62.         return r * r * Math.PI;
  63.     }
  64. }
  65.  
  66. class Rectangule {
  67.     private int h;
  68.     private int w;
  69.  
  70.     Rectangule() {
  71.         h = 1;
  72.         w = 1;
  73.     }
  74.  
  75.     Rectangule(int a, int b) {
  76.         h = a;
  77.         w = b;
  78.     }
  79.  
  80.     int getArea() {
  81.         return h * w;
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement