Write a java program to Flush Characters.

Write a program to read a string from the user and remove all the alphabets and spaces from the String, and only store special characters and digit in the output String. Print the output string.

The return type (String) should return the character removed string.

Input and Output Format:

Input consists of string.

The output consists of a String (character removed string).

Refer sample output for formatting specifications.

Sample Input :


Sample Output :


Flush Characters in Java.

import java.util.Scanner;

public class Main {
   * @param args
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s1 = sc.nextLine();

    String s2 = getvalues(s1);

  public static String getvalues(String s1) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < s1.length(); i++) {
      char a = s1.charAt(i);
      if (!Character.isAlphabetic(a))
    return sb.toString();

You May Also Like These Posts:

Leave a Reply

Your email address will not be published.

sixteen − 5 =