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 :

codebun$#45Ant

Sample Output :

$#45

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);
    System.out.println(s2);
  }

  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))
        sb.append(a);
    }
    return sb.toString();
  }
}

Add a Comment

Your email address will not be published. Required fields are marked *

6 − 3 =