Write a program that replaces two or more consecutive blanks in a string by a
single
blank. For example, if the input is
Grim return to the planet of apes !!
the output should be
Grim return to the planet of apes!!
import java.util.Scanner;
public class ReplaceBlanks {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String text=input.nextLine();
System.out.println(new String(text).trim().replaceAll("\\s{2,}", " "));
input.close();
}
}
Comments
Dear Bha , if you have serious assignment that requires large amount
of work and hence cannot be done for free you can submit it as assignment and our
experts will surely assist you.
Can you explain the logic in it
Leave a comment