Remove extra spaces

Report a typo

Write a program that reads a text and removes all extra spaces. The program must replace all repeating spaces and tabulations between words with a single space character (' ').

Use the provided template. Please, use regular expressions to solve the task.

Sample Input 1:

Just                  a                   text

Sample Output 1:

Just a text

Sample Input 2:

   The 	Java   language was initially called Oak after an oak tree 		that stood     outside Gosling's  office. Later the project went    by the     name Green   and was finally 	renamed Java, 	from Java coffee.  

Sample Output 2:

The Java language was initially called Oak after an oak tree that stood outside Gosling's office. Later the project went by the name Green and was finally renamed Java, from Java coffee.
Write a program in Java 17
import java.util.Scanner;

class RemoveExtraSpacesProblem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

String text = scanner.nextLine();

// write your code here
}
}
___

Create a free account to access the full topic