SHARE
TWEET

Untitled

a guest Dec 6th, 2019 88 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.         boolean isFind = false;
  19.  
  20.         long[] numbers = new long[words.length];
  21.         for(int i = 0; i < words.length; i ++){
  22.             numbers[i] = Integer.parseInt(words[i]);
  23.             if(numbers[i] % 2 == 0){
  24.                 long evenNumber = numbers[i];
  25.                 if(evenNumber > maxEvenNumber){
  26.                     maxEvenNumber = evenNumber;
  27.                 }
  28.                 isFind = true;
  29.             }
  30.         }
  31.         if(isFind){
  32.             System.out.println(maxEvenNumber);
  33.         }else {
  34.             System.out.print(-1);
  35.         }
  36.  
  37.     }
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top