You are on page 1of 1

14. Find factors of a given number and display in a textarea and also find if the given no.

is a perfect no. A perfect no’s sum of factors excluding itself is equal to the number
e.g. 6 (factors 1+2+3 = 6 which is same as 6)

DESIGN OUTPUT

FIND BUTTON:-
int N=Integer.parseInt(jTextField1.getText());

int sum=0;

for(int x=1;x<=N;x++)

{if(N%x==0)

{ sum=sum+x;

jTextArea1.append(x+" "); } }

jTextField2.setText(sum+"");

if(N==sum-N)

jTextField3.setText("Yes,its a perfect no.");

else

jTextField3.setText("No,its not a perfect no.");

CLEAR BUTTON:-
jTextField1.setText("");

jTextArea1.setText("");

jTextField2.setText("");

jTextField3.setText("");

CLOSE BUTTON:-
System.exit(0);

You might also like