Can any 1 provide me with an example of a program in Java of pure methods.
Answers
Answered by
2
Answer:
Java program of pure methods.
Explanation:
function purefunc(value){
return value * value;
}
var pureout= [ ] ;
for(var i = 0; i < 5; i++){
pureout.push(pureFunc(5));
}
c onsole.log("Pure result: " + pureout); // result is consistent with same input
Answered by
0
A pure program in Java is one whose execution has no effects at all.
- A pure program returns the value of the function and is dependent only on the input parameters which are passed into the function.
- For example - public class ObjectWithAPureFunction{ public int sum(int b, int c ) return b + c; }
- The value returned by the sum) (function depends only on the input parameters. Note also that the sum) (does not have any side effects, meaning it does not modify any state (variables) anywhere outside the function.
Similar questions