-4
public class FunWithArrays {
    public static void main(String[] args) {
        int[] myFunArray = {7, 10, 3, 0, 615, -1000};
        int i;
 //minimum 
    int min;
    min = myFunArray[0];
    for (i=0; i < myFunArray. length; i++) {
    if (myFunArray[i] < min) {
        min = myFunArray[i];
    } 
 }
 //maximum 
 int max;
 max= myFunArray[0];
 for (i=1; i < myFunArray. length; i++) {
    if (myFunArray[i] > max) {
        max = myFunArray[i];
        }
    }
 System.out.println("minimum = " + min + " maximum = " + max);
        //mean without outliers
        double noOutliersMean = 0;
        for (i=0; i < myFunArray.length; i++){
            noOutliersMean = ((sum - (max + min)) /myFunArray.length );
            if ( myFunArray.length < 3){
                System.out.println("not enough numbers");
            }
        }
        System.out.println("Mean without Outliers: " +noOutliersMean);

        //Array reversed
        int[] reversed = myFunArray;
        for(int i1 = reversed.length - 1; i1 >= 0 ; i1--) {
            System.out.println( "Reversed " + reversed[i1]);
        }
    }
}

For the mean without the outliers (max and min) the answer should be 5 my line of code gives me 1.333. What am i doing wrong?

2nd question regarding the array reversed, when printed out it gives me the right answer but each number on a separate line. How do i get it to be on 1 line in the format of ; reversed: [-1000,615,0,3,10,7]

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
AlexSK
  • 1
  • 3

2 Answers2

0

the answer to your second question is don't print using

println

, just use print

The code should be:

System.our.print("Reversed: [")
for(int i1 = reversed.length - 1; i1 >= 0 ; i1--) {
    System.out.print(reversed[i1]);
    if(i1>0){
       System.our.print(",");
    }
}
System.out.print("]");

To answer your first question you need to provide the following:

How you are calculating sum, max and min. Even though you have mentioned without max and min.. you still are using it in your code

0

Think about the logic of the code when you manipulated the array... you will see that the mean with no min or max is the same as: the mean excluding the elements at index0 and index length-1 if the array were sorted, so that is what you have to do

  1. sort the array
  2. loop excluding 1st and last
  3. calculate the mean

Example:

int[] myFunArray = { 7, 10, 3, 0, 615, -1000 };
// unsorted { 7, 10, 3, 0, 615, -1000 };
// sorted { -1000, 0, 3, 7, 10, 615 };

Arrays.sort(myFunArray);
System.out.println(Arrays.toString(myFunArray));
int acumm = 0;
double mean = 0.0;
for (int i = 1; i < myFunArray.length - 1; i++) {
    acumm += myFunArray[i];
}
mean = acumm / (myFunArray.length - 2);
System.out.println(mean);
Community
  • 1
  • 1
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97