1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| package exercices;
import utilitaires.Keyboard;
public class exercice13 {
public static boolean parfait(double n)
{
int i = 1 ;
double sum = 0 ;
boolean resultat = false ;
while (i < n - 1)
{
if (n % i == 0)
{sum = sum + i;}
i++;
}
if (sum == n)
{resultat = true;}
else
{resultat = false;}
return resultat ;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int n ;
double i = 1 , j = 0;
System.out.println("Quel est l'entier naturel non nul ? :");
n = Keyboard.readInt();
while (n == 0)
{
System.out.println("Quel est l'entier naturel non nul ? :");
n = Keyboard.readInt();
}
while (j < n)
{
if (parfait(i)== true )
{j++;
System.out.println("Le " + j + "er nombre parfait est " + i);
}
i++;
}
}
} |
Partager