(a) Write a java program to determine if a number is perfect. Your program must read...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
(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 (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
Expert Answer:
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these computer network questions
-
A corporation is evaluating the following projects. The companys WACC is 10.50%. If the projects are NOT mutually exclusive, which should it accept? If the projects ARE mutually exclusive, which...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Explain informally the difference between Godel's completeness theorem and his first incompleteness theorem. [8 marks] (b) State the meaning of Hoare triples {P} C {Q} in separation logic. [3 marks]...
-
Bollobs and Chung proposed a hybrid model that combines a 2-ring on \(V\) vertices ( \(V\) is even), plus a random matching. A matching is a graph in which every vertex has degree 1. To generate a...
-
Describe how the number of comparisons used in the worst case changes when these algorithms are used to search for an element of a list when the size of the list doubles from n to 2n, where n is a...
-
The load in Figure P8-69. needs to be designed for maximum power transfer. (a) Find the maximum available average power at the interface shown in the figure. (b) Specify the load required to extract...
-
The two-dimensional heat equation is solved in a rectangular domain \(0
-
The December 31, 2013, adjusted trial balance of Success Systems (reflecting its transactions from October through December of 2013) follows. Required 1. Record and post the necessary closing entries...
-
2. Statistical measures of standalone risk Remember, the expected value of a probability distribution is a statistical measure of the average (mean) value expected to occur during all possible...
-
12 (1 point) A pair of variables, x and y have a correlation coefficient of 0.60. What percent of the variation in y is explained by the variation in x? Your
-
6. When 30,000 units are produced, variable costs are $10 per unit. Therefore, when 20,000 units are produced ?1)variable costs will remain at $10 per unit 2)variable costs will total $60,000...
-
Share at least two ways to improve customer satisfaction and explain why each improvement will be beneficial. Explore resources within your hypothetical community and share at least one ,then discuss...
-
How do symbiotic relationships at the organismal level, such as those involving microbiomes, contribute to the health, physiology, and evolution of their host organisms ?
-
What must accountants understand about an organization's structure and business environment to perform effectively in that organization?
-
What is a requisition? What is a butcher test and provide two benefits of it. (2) If you prepare 12 salmon dishes and your sales total 12 this is usually considered good sales forecasting. Provide a...
-
For this assignment, imagine we are the supervisor of case managers who come to us for support and guidance. You have noticed a theme of questions that are frequently asked, which mostly surround...
-
9.Consider the reaction 3NO2(g)+H2O=2HNO3(aq)+NO(g) where Delta H=-137 kJ.How many kilojoules are released when 92.3g of NO2 reacts?
-
Your supervisor has asked you to research the following situation concerning Owen and Lisa Cordoncillo. Owen and Lisa are brother and sister. In May 2012, Owen and Lisa exchange business pickup...
-
William sold Section 1245 property for $25,000 in 2012. The property cost $35,000 when it was purchased 5 years ago. The depreciation claimed on the property was $16,000. a. Calculate the adjusted...
-
Abigail (Abby) Boxer is a single mother working as a civilian accountant for the U.S. Army. Her Social Security number is 676-73-3311 and she lives at 3456 Alamo Way, San Antonio, TX 78249. Helen,...
-
You are valuing the equity in a firm with \($800\) million (face value) in debt with an average duration of six years and assets with an estimated value of \($400\) million. The standard deviation in...
-
Marion Manufacturing, a steel company, announces that it will be taking a major restructuring charge that will lower earnings this year by $500 million. Assume that the charge is not tax deductible...
-
General Systems is a firm that manufactures personal computers. As a top manager in the firm, you are considering changes in the way the firm is run. Currently, the firm has after-tax operating...
Study smarter with the SolutionInn App