Write a program in java to print the non blank characters present in the string.

 THE FOLLOWING PROGRAM SEGMENT SHOWS HOW TO COUNT AND PRINT THE NON BLANK CHARACTERS IN THE STRING IN JAVA USING SCANNER CLASS.

import java.util.*;

class i

{

    public static void main (String args[])

    {

        Scanner ob = new Scanner (System.in);

        String s; int c = 0;

        System.out.println("Enter a string");

        s = ob.nextLine();

        for(int i = 0; i < s.length(); i++)

        {

            char ch = s.charAt(i);

            if( ch != ' ')

            {

                c++;

            }

            System.out.println("No of non blank characters " +c);

           

            }

        }

    }

        Hope you guys found it helpful.

Please share it with your friends and leave a comment in the comment section below.

Follow https://askrisfor.blogspot.com/ for more such programs.

Thank you !!!

Visit again.  

Comments

Popular Posts