1
I am developing a challenge in Java, and I need to create a function that calculates an irreducible fraction to solve the problem.
I created a function from some search but the function does not correctly calculate the value.
Would anyone know the problem with my job?
Follow below function code.
Java function
public void irreductibleFraction(int numerador, int denominador)
{
int cont = 1;
while ((numerador % cont == 0) && (denominador % cont == 0))
{
if(denominador != 0)
{
numerador /= cont;
denominador /= cont;
cont++;
}
else
{
break;
}
}
System.out.println(numerador + "/" + denominador);
}
What would be the expected value? Give an example pf.
– Filipe L. Constante
Mathematically, the easiest way would be to divide both by MDC
– Jefferson Quesado
0/1 but returns me 1/0. With the numbers I am testing, which were made available by the challenge.
– Laura Regina