CS 2130 Computational structures Write Java programs that use command-line input
ID: 3908875 • Letter: C
Question
CS 2130 Computational structures
Write Java programs that use command-line input and call the following integer functions. All calculations for each function should be encapsulated within the function. Use a long datatype instead of int for all input and output variables. Do NOT use string variables in any of the algorithms. A sample main program will be provided as an example.
Turn in source code for each function, along with test output.For each of the above functions, state whether or not the function is one-to-one. Justify your answers. If a function is not one-to-one, show two inputs that have the same output.
1. SumOfDivisors: The input variable X is a positive integer. The function should return as Y the sum of the divisors of X. For example, if X is 10, then Y is 1+2+5+10=18. If X is 23, then Y is 24. Whenever Y = 2X, X is called a perfect number.
Test your function with the following inputs:X = 6 X = 277 X = 3443 X = 8128 X = 298760
Explanation / Answer
The function is nbot a one-to-one function as for X = 6 and X = 11, the function gives same output(12).
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.