Computer Science, asked by raghuvanshikhushi584, 3 months ago



Wap to input an array of size 10 and print only those elements which are perfect

Answers

Answered by kamalrajatjoshi94
1

Answer:

Program:-

import java.util.*;

public class Perfect

{

public static void main(String args[ ])

{

Scanner in=new Scanner(System.in);

int s=0;

int a[ ]=new int[10];

System.out.println("Enter the numbers");

for(int i=0;i<a.length;i++)

{

a[i]=in.nextInt();

}

System.out.println("Perfect numbers are:-");

for(int i=0;i<a.length;i++)

{

for(int j=1;j<a[i];j++)

{

if(a[i]%j==0)

{

s=s+j;

}

}

if(s==a[i])

System.out.println(a[i]);

}

}

}

Similar questions