<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">//discussed inside-out rule and assertions

public class Middle {

	int temp;
	
	/** Returns the value that, if a, b, and c were sorted,
	  * would be in the middle. */
	public static int middle(int a, int b, int c) {

		// Swap b and c if out of order
		if (b &gt; c) {
			// temp refers to local var, not field
			// (inside out rule)
			
			// better to declare as locally as possible.
			int temp = b;
			b = c;
			c = temp;
		}

		// prefer assert statements to comments.  Instead of a "b &lt;= c" comment, write
		assert b &lt;= c;
		
		if (a &lt;= b) {
			assert a &lt;= b &amp;&amp; b &lt;= c;
			return b;
		}
		
		assert a &gt;= b &amp;&amp; c &gt;= b; 
		
		return Math.min(a, c);
	}
}
</pre></body></html>