Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PrimeNumbers {
  4.  
  5. public static void main(String[] args) {
  6. Scanner scan = new Scanner(System.in);
  7.  
  8. String input = scan.nextLine().replace(".", " ");
  9. String[] arr = input.split(" ");
  10.  
  11. int maxNum = -1;
  12. int num = -1;
  13. boolean isNum = true;
  14. for (int i = 0; i < arr.length; i++) {
  15. try {
  16. num = Integer.parseInt(arr[i]);
  17. } catch (NumberFormatException e) {
  18. isNum = false;
  19. }
  20. if (isNum) {
  21. num = Integer.parseInt(arr[i]);
  22. }
  23. if (num % 2 == 0 && num > maxNum) {
  24. maxNum = num;
  25. }
  26. isNum = true;
  27. }
  28. if (maxNum != -1) {
  29. System.out.println(maxNum);
  30. } else {
  31. System.out.println("-1");
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement