Guest User

Untitled

a guest
Dec 6th, 2019
111
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class EvenNumbers {
  4. public static void main(String[] args){
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String input = scanner.nextLine();
  8.  
  9. input = input.replaceAll("[^-?0-9]+", " ").trim();
  10. String[] words = input.split(" ");
  11.  
  12. if(input.equals("")){
  13. System.out.print(-1);
  14. return;
  15. }
  16.  
  17. Long maxEvenNumber = Long.MIN_VALUE;
  18.  
  19. long[] numbers = new long[words.length];
  20. for(int i = 0; i < words.length; i ++){
  21. numbers[i] = Integer.parseInt(words[i]);
  22. if(numbers[i] % 2 == 0){
  23. long evenNumber = numbers[i];
  24. if(evenNumber > maxEvenNumber){
  25. maxEvenNumber = evenNumber;
  26. }
  27. }
  28. }
  29. System.out.println(maxEvenNumber);
  30. }
  31. }
RAW Paste Data