Lost in life
Lost in life
Lost in life
Lost in life
It certainly does sum them up but the sum is not being returned.Suane Mane wrote:I don't know how I'm supposed to write a return statement then. I thought the parts like:
declare what needs to be done when the method is accessed and I thought x was the array? And thus it would go through all array items and just add them up.
Lost in life
Lost in life
Lost in life
Kyle Prouty wrote:
I would take a step back and think about what the exercise is trying to achieve.
Here are some questions they are asking...
We are given a static class that has a main, we know that this class will start the execution of our program. Do I know how to compile and run a java class? We are told to create a class. Do I know how to create a class? We are told to add 4 static methods to that class. We are given the complete function definition, nice! Do I know what methods of a class are? Do I know what public and static mean? Do I know what the double following public static means? Do I know what sum(double[] x) means? We keep seeing static. What does that mean when my class is static. How does that change how methods are called? Do I know how to iterate through an array? Do I know how to return a value from a method?
Lost in life
Careful; that code is broken and will fall over horribly if you pass a 0‑element array to it.Kyle Prouty wrote:Here is a fun Java 8 way to do it. . . .
Kyle Prouty wrote:
Here is a fun Java 8 way to do it.
Lost in life
Please look here; I only worked out the average.Suane Mane wrote:. . . I have no idea what final, stream or getasdouble mean. . . .
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
|