Only Alphabets and Space
Given a String S, remove all the special characters and numbers from S and print.
Input Format:
The first line contains the string S
The first line contains the string S
Output Format:
The first line contains the string with only alphabets and spaces.
The first line contains the string with only alphabets and spaces.
Boundary Conditions:
1 < Length of S < 1000
1 < Length of S < 1000
Example Input/Output 1:
Input:
Hello #$ World!
Input:
Hello #$ World!
Output:
Hello World
Hello World
Example Input/Output 2:
Input:
Grand2017
Input:
Grand2017
Output:
Grand
Grand
Code:
import java.util.*;
public class Hello {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int i;
for(i=0;i<str.length();i++)
if((str.charAt(i)>='a'&&str.charAt(i)<='z')||(str.charAt(i)>='A'&&str.charAt(i)<='Z')||
str.charAt(i)==' ')
System.out.print(str.charAt(i));
}
}
}
Please do comment If u have any Queries!
No comments:
Post a Comment