chillurbrain

Task1Lab5_1

Dec 8th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class Task1_5_1 {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.         int m = 0, n = 0, gcd;
  7.         int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
  8.         m = (a * d) + (c * b);
  9.         n = b * d;
  10.         gcd = GCD(m, n);
  11.         m /= gcd;
  12.         n /= gcd;
  13.         System.out.println(m + " " + n);
  14.     }
  15.  
  16.     public static int GCD(int a, int b) {
  17.         if (b == 0)
  18.             return a;
  19.         else return GCD(b, a % b);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment