DEV/DEV2.1/TD1/Fraction.java

39 lines
578 B
Java
Raw Normal View History

2023-02-10 11:52:05 +01:00
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;
}
}