fork download
  1. public class Main {
  2. public static void main(String[] args) {
  3. // An array storing different ages
  4. int ages[] = {20, 22, 18, 35, 48, 26, 87, 70};
  5.  
  6. // Get the length of the array
  7. int length = ages.length;
  8.  
  9. // Create a 'lowest age' variable and assign the first array element of ages to it
  10. int lowestAge = ages[0];
  11.  
  12. // Loop through the elements of the ages array to find the lowest age
  13. for (int age : ages) {
  14. // Check if the current age is smaller than the current 'lowest age'
  15. if (lowestAge > age) {
  16. // If the smaller age is found, update 'lowest age' with that element
  17. lowestAge = age;
  18. }
  19. }
  20.  
  21. // Output the value of the lowest age
  22. System.out.println("The lowest age in the array is: " + lowestAge);
  23. }
  24. }
  25.  
Success #stdin #stdout 0.1s 55664KB
stdin
Standard input is empty
stdout
The lowest age in the array is: 18