Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class Zada4i3 {
  5. public static void main(String args[]) {
  6.  
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String[] words = scanner.nextLine().split(" ");
  10. int count = 0;
  11. String[] wordsDis = new String[count];
  12.  
  13.  
  14. for (int i = 0; i < words.length - 1; i++) {
  15.  
  16. if (!words[i].equals(words[i + 1])) {
  17. for (int j = i+1; j < words.length; j++) {
  18.  
  19. if (!words[i].equals(words[j])) {
  20. count++;
  21. }
  22.  
  23. if (count == (words.length - 1) - i) {
  24. System.out.println(words[i]);
  25. count = 0;
  26. }
  27.  
  28. }
  29.  
  30. }
  31. }
  32.  
  33. //last element
  34. int last = 0;
  35. for (int k = 0; k < words.length - 1; k++) {
  36. if (!words[words.length - 1].equals(words[k])) {
  37. last++;
  38. }
  39.  
  40. if (last == words.length-1){
  41. System.out.println(words[words.length - 1]);
  42.  
  43. }
  44.  
  45. }
  46.  
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement