Write a program that removes all spaces from the given input. Ex: If the input is: Hello my name is John. the output is: HellomynameisJohn.
The program needs to be in Java
Source Code- In JAVA
import java.util.Scanner;
class Main {
public static void main(String[] args) {
// create an object of Scanner
Scanner scr = new Scanner(System.in);
System.out.println("Enter the string of your choice");
// take the input
String input = scr.nextLine();
System.out.println("Original String: " + input);
// remove white spaces
input = input.replaceAll("\\s", "");
System.out.println("Final String: " + input);
scr.close();
}
}
Hope I answered the question.
If you have any doubts, or queries, feel free to ask
I'll respond to you as soon as I can.
Have a nice day
Get Answers For Free
Most questions answered within 1 hours.