get Width and Height ratio String - Android java.lang

Android examples for java.lang:Integer

Description

get Width and Height ratio String

Demo Code


//package com.java2s;

public class Main {

    public static String getWHratioString(int width, int height) {
        int gcd = gcd(width, height);
        int w = width / gcd;
        int h = height / gcd;
        return w + ":" + h;
    }//from   w w w. j  a  v  a 2 s .  co m

    public static int gcd(int a, int b) {
        int min = a;
        int max = b;
        if (a > b) {
            min = b;
            max = a;
        }
        if (min == 0)
            return max;
        else
            return gcd(min, max - min);
    }
}

Related Tutorials