Advertisement
Ligh7_of_H3av3n

opravn cod

Feb 12th, 2024
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.34 KB | None | 0 0
  1. if (firstElement.equals(secondElement)) {
  2.     // Remove elements by index, not by value
  3.     list.remove(indexes[1]); // Remove the second element first to avoid index shifting
  4.     list.remove(indexes[0]);
  5.     System.out.printf("Congrats! You have found matching elements - %s!\n", firstElement);
  6. } else {
  7.     System.out.println("Try again!");
  8. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement