Question: (a) Write a java program to determine if a number is perfect. Your program must read the given integer and print whether it is
(a) Write a java program to determine if a number is perfect. Your program must read the given integer and print whether it is perfect or not. A perfect number is defined as a positive integer (>0) such that the sum of its factors (including 1, but not the number itself), add up to the number. For example 6 (= 1+2+3) is a perfect number. Use the following template: import java.util.Scanner; public class Exla{ } public static void main(String[] args) { //rest of the code here (b) Modify the above program so that it uses a method is perfect to determine if a given integer is perfect or not. import java.util.Scanner; public class Exlb{ public static void main(String[] args) { } //rest of the code here public static boolean isPerfect(int n) { //code here } } (c) Modify 1(b) to print all perfect numbers from 1 to 10,000. Call this program: Exlc (d) Determine the execution time for the core part of the program (finding all perfect numbers between 1 and 10,000) in 1(c). You can use the following code template to obtain the execution time: long startTime, endTime, executionTime; startTime = System.currentTimeMillis(); //code segment endTime = System.currentTimeMillis(); wwwww executionTime = endTime wwww startTime; The above segment will give the time for executing the code segment in milliseconds. Call this program: Exld
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
