Skip to content

Instantly share code, notes, and snippets.

@gitaficionado
Created March 9, 2021 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitaficionado/1ed86f78f491a14d2f4fe28a7d08a81d to your computer and use it in GitHub Desktop.
Save gitaficionado/1ed86f78f491a14d2f4fe28a7d08a81d to your computer and use it in GitHub Desktop.
Beginning structure of NumStatsArray
public class NumStatsArray{
//Create a private array as a double as final
________________________________________
public NumStatsArray(double[] a){
arr = a;
}
//Iterate through and cancatenate all values except last and follow each with a comma. Creat string with a "{" the beginning and end it with a "}".
public String toString()
//Create a method that returns average fo all values as a double. Be sure to crate a sum variable as a double.
/* Create min and max variables set to first value in array. Then, iterate all values and update max every time new
largest value found. Finally, update min every time new smallest value found and return min - max.
*/
// Create booleans for ascending/descending sequence as true.
/* Iterates through all except the first value in the array, and checks if
* current value is smaller than the previous (meaning arr is not decreasing
* or is greater than the previous (meaning arr is not increasing).
*/
// check increasing first, so if all are same, 1 is returned
if(increasing)
return 1;
if(decreasing)
return -1;
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment