Advertisement
Guest User

Untitled

a guest
Mar 9th, 2022
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class SignalFromSpace {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6.  
  7. String input = scan.nextLine();
  8. char[] initialMessage = new char[input.length()];
  9. String finalMessage = "";
  10.  
  11. for (int i = 0; i < initialMessage.length; i++) {
  12. initialMessage[i] = input.charAt(i);
  13. }
  14.  
  15. for (int k = 1; k <= initialMessage.length - 1; k++) {
  16. if (initialMessage[k] != initialMessage[k - 1]) {
  17. finalMessage += initialMessage[k - 1];
  18. }
  19. if (k == initialMessage.length - 1) {
  20. if (initialMessage[k] != initialMessage[k - 1]) {
  21. finalMessage += initialMessage[k];
  22. }
  23. }
  24. }
  25. System.out.println(finalMessage);
  26. }
  27. }
  28.  
Advertisement
RAW Paste Data Copied
Advertisement