Signal from space

Report a typo

Our satellite caught a signal from space. It is an array of strings but we can't read the messages because there are too many disturbances in the form of ~ symbols. Your task is to implement a method that takes an array of strings as a parameter, removes the ~ symbol from each string, and returns the result.

Sample input 1:

4~ 8~ ~~15~ 16~ 2~~3 ~~4~~*~

Sample output 1:

4 8 15 16 23 4*

Sample input 2:

~H~ow d~~if~fic~~ul~~t~ i~~t ~is~ to ma~~ke p~opco~rn in ~ze~ro gr~av~it~y.

Sample output 2:

How difficult it is to make popcorn in zero gravity.

Sample Input 1:

4~ 8~ ~~15~ 16~ 2~~3 ~~4~~*~

Sample Output 1:

4 8 15 16 23 4*
Write a program in Java 17
import java.util.Scanner;

public class Main {
public static String[] decipherCosmicSignal(String[] spaceSignalArray) {
// write your code here
return null;
}

// Don't change the code below
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[] encryptedSpaceSignalArray = scanner.nextLine().split("\\s");
String[] spaceSignalArray = decipherCosmicSignal(encryptedSpaceSignalArray);
StringBuilder spaceMessage = new StringBuilder();
for (String signal : spaceSignalArray) {
spaceMessage.append(signal).append("\s");
}
System.out.println(spaceMessage.toString().trim());
}
}
___

Create a free account to access the full topic