Skip to content

Instantly share code, notes, and snippets.

@gitaficionado
Last active March 9, 2021 21:29
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/5b220d850a627bec30562f6e13cea450 to your computer and use it in GitHub Desktop.
Save gitaficionado/5b220d850a627bec30562f6e13cea450 to your computer and use it in GitHub Desktop.
Use the following java file to begin your NumStatsArray class.
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.
Create 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).
*/
for(int i = 1; i < arr.length; i++)
{
if(arr[i] < arr[i-1])
{
increasing = false;
}
if(arr[i] > arr[i-1])
{
decreasing = false;
}
}
// 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