Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I discard the largest and smallest numbers when I calculate the arithmetic mean?
    primarykey
    data
    text
    <p>My question is about discarding the largest and smallest number when my program calculates an arithmetic mean.</p> <p>This is my code sample:</p> <pre><code>public static void main(String[] args) { int k; int r; int thelargest; int thesmallest; Scanner input = new Scanner(System.in); System.out.println("Enter the list of number : "); String input2 = input.nextLine(); String[] numbers = input2.split(" "); int[] result = new int[numbers.length]; for (r = 0; r &lt; numbers.length; r++) { result[r] = Integer.parseInt(numbers[r]); } for (k = 0; k &lt; result.length; k++) { System.out.print(""); System.out.println(result[k]); } System.out.println(" LargestNumber : " + TheLargestNumber(result)); System.out.println(" SmallestNumber : " + TheSmallestNumber(result)); thelargest = TheLargestNumber(result); thesmallest = TheSmallestNumber(result); System.out.println("The Arithmetic Mean : " + AirthmeticMean(result)); } public static int TheSmallestNumber(int[] series) { int thesmallest = series[0]; for (int i = 1; i &lt; series.length; i++) { if (series[i] &lt; thesmallest) { thesmallest = series[i]; } } return thesmallest; } public static int TheLargestNumber(int[] series) { int thelargest = series[0]; for (int i = 1; i &lt; series.length; i++) { if (series[i] &gt; thelargest) { thelargest = series[i]; } } return thelargest; } public static float AirthmeticMean(int[] result) { int sum = 0; for (int i = 0; i &lt; result.length; i++) { sum += result[i]; } return (float) sum / result.length; } </code></pre> <p>I tried to find the way and I wrote this sample but I don't know how to embed this code sample:</p> <pre><code> for (int i = 0; i &lt; result.length; i++) { if (series[i] != thesmallest &amp;&amp; series[i] != thelargest) { total = total + seriess[i]; } } </code></pre> <p>Will this code sample be helpful to me?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload