12-arrays.java 683 B

12345678910111213141516171819202122232425262728293031323334
  1. import java.util.Scanner;
  2. class Main {
  3. public static void main(String[] args) {
  4. int[] numbers = new int[4];
  5. for (int i = 0; i < numbers.length; i++) {
  6. numbers[i] = readValue("Ingresa el número " + (i + 1) + ": ");
  7. }
  8. int max = getMaxValue(numbers);
  9. System.out.println("El valor máximo es: " + max);
  10. }
  11. public static int readValue(String message) {
  12. System.out.print(message);
  13. return new Scanner(System.in).nextInt();
  14. }
  15. public static int getMaxValue(int[] numbers) {
  16. int max = numbers[0];
  17. for (int i = 0; i < numbers.length; i++) {
  18. if (numbers[i] > max) {
  19. max = numbers[i];
  20. }
  21. }
  22. return max;
  23. }
  24. }