39 lines
578 B
Java
39 lines
578 B
Java
public class Fraction
|
|
{
|
|
private int numerateur;
|
|
private int denominateur;
|
|
|
|
public Fraction(int n, int d)
|
|
{
|
|
this.numerateur = n;
|
|
this.denominateur = d;
|
|
}
|
|
|
|
private static int pgcd(int a, int b)
|
|
{
|
|
int pgdc=0;
|
|
for ( int i = 0 ; i <= a && i <= b ; i++ )
|
|
{
|
|
if(a%i==0 && b%i==0)
|
|
{
|
|
pgcd = i;
|
|
}
|
|
}
|
|
return pgcd;
|
|
}
|
|
|
|
public void reduire()
|
|
{
|
|
int pgcd = Fraction.pgcd(this.denominateur,this.numerateur);
|
|
this.denominateur/=pgcd;
|
|
this.numerateur/=pgcd;
|
|
}
|
|
|
|
public
|
|
|
|
public String toString()
|
|
{
|
|
return this.numerateur+"/"+this.denominateur;
|
|
}
|
|
|
|
} |