Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class NumeroPerfeito {
- public static void main(String[] args) {
- int n = -1;
- do {
- n = Console.lerInt(new String("Digite um número: "));
- if ( Perfeito(n) )
- Console.escrever(new String("O número "+n+" é um número perfeito."));
- else
- Console.escrever(new String("O número "+n+" não é um número perfeito."));
- Console.pulaLinha();
- } while (n != 0);
- }
- private static boolean Perfeito(int n)
- {
- int soma=0,contador=1;
- boolean perfeito=false;
- for( contador=1;contador<n;contador++){
- if(n%contador==0){
- soma+=contador;
- }if (soma==n){
- perfeito=true;
- }
- }
- return perfeito;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement