fork(7) download
  1. class Example
  2. {
  3. public static void main(String[] args) throws Exception {
  4. int[] values = {5, 1, 2};
  5. int smallest = Integer.MAX_VALUE;
  6. int largest = Integer.MIN_VALUE;
  7. for (int value : values) {
  8. if (value < smallest) {
  9. smallest = value;
  10. } else if (value > largest) {
  11. largest = value;
  12. }
  13. }
  14. System.out.println(smallest + ", " + largest); // 1, 2 -- WRONG
  15. }
  16. }
  17.  
Success #stdin #stdout 0.05s 2184192KB
stdin
Standard input is empty
stdout
1, 2