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