class Example
{
int[] values = {5, 1, 2};
int smallest = values[0];
int largest = values[0];
for (int n = 1; n < values.length; ++n) {
int value = values[n];
if (value < smallest) {
smallest = value;
} else if (value > largest) {
largest = value;
}
}
System.
out.
println(smallest
+ ", " + largest
); // 1, 5 }
}
Y2xhc3MgRXhhbXBsZQp7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB0aHJvd3MgRXhjZXB0aW9uIHsKICAgICAgICBpbnRbXSB2YWx1ZXMgPSB7NSwgMSwgMn07CiAgICAgICAgaW50IHNtYWxsZXN0ID0gdmFsdWVzWzBdOwogICAgICAgIGludCBsYXJnZXN0ICA9IHZhbHVlc1swXTsKICAgICAgICBmb3IgKGludCBuID0gMTsgbiA8IHZhbHVlcy5sZW5ndGg7ICsrbikgewogICAgICAgICAgICBpbnQgdmFsdWUgPSB2YWx1ZXNbbl07CiAgICAgICAgICAgIGlmICh2YWx1ZSA8IHNtYWxsZXN0KSB7CiAgICAgICAgICAgICAgICBzbWFsbGVzdCA9IHZhbHVlOwogICAgICAgICAgICB9IGVsc2UgaWYgKHZhbHVlID4gbGFyZ2VzdCkgewogICAgICAgICAgICAgICAgbGFyZ2VzdCA9IHZhbHVlOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihzbWFsbGVzdCArICIsICIgKyBsYXJnZXN0KTsgLy8gMSwgNQogICAgfQp9