Breaking

Monday, 6 November 2017

Only Alphabets and Space


               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
Output Format:
The first line contains the string with only alphabets and spaces.
Boundary Conditions:
1 < Length of S < 1000
Example Input/Output 1:
Input:
Hello #$ World!
Output:
Hello  World
Example Input/Output 2:
Input:
Grand2017
Output:
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

Like