exercise on java coding, Exercises of Computer science

Practice exercise on java coding

Typology: Exercises

2024/2025

Uploaded on 07/16/2025

praveena-k-j-kiran
praveena-k-j-kiran 🇮🇳

1 document

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Perfect Number Function Analysis
The following is a function of some class. It returns 1 if the number is a perfect number
otherwise it returns 0.
/* A perfect number is a number which is equal to the sum of its factors other than the number
itself */
int perfectNo(int n)
{
int ??1?
for (int j = 1; ??2?; j++)
{
if (??3?)
sum ??4?;
}
if (??5?)
return 1;
else
return 0;
}
(i) What is the expression/value at ??1?
(ii) What is the expression/value at ??2?
(iii) What is the expression/value at ??3?
(iv) What is the expression/value at ??4?
(v) What is the expression/value at ??5?

Partial preview of the text

Download exercise on java coding and more Exercises Computer science in PDF only on Docsity!

Perfect Number Function Analysis

The following is a function of some class. It returns 1 if the number is a perfect number otherwise it returns 0. /* A perfect number is a number which is equal to the sum of its factors other than the number itself */ int perfectNo(int n) { int ??1? for (int j = 1; ??2?; j++) { if (??3?) sum ??4?; } if (??5?) return 1; else return 0; } (i) What is the expression/value at ??1? (ii) What is the expression/value at ??2? (iii) What is the expression/value at ??3? (iv) What is the expression/value at ??4? (v) What is the expression/value at ??5?