Getting the smallest possible integer ratio between two numbers
You need to find the GCD and then divide both numbers by that.

Euclid's algorithm is the classic way to do this.

int gcd(int p, int q) {
    if (q == 0) return p;
    else return gcd(q, p % q);
}

void ratio(int a, int b) {
   final int gcd = gcd(a,b);
   System.out.println(a/gcd + " " + b/gcd);
}


If you want to swap a and b to have the biggest first then that's easy too

void ratio(int a, int b) {
   final int gcd = gcd(a,b);
   if(a &gt; b) {
       showAnswer(a/gcd, b/gcd);
   } else {
       showAnswer(b/gcd, a/gcd);
   }
}

void showAnswer(int a, int b) {
   System.out.println(a + " " + b);
}