Write a program in java to input a string and print the number of A's or a's present in the string.

 THE FOLLOWING PROGRAM SEGMENT SHOWS HOW TO PRINT THE NUMBER OF a's OR A's FROM THE ENTERED STRING.

import java.util.*;

class PRINT

{

    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 == 'A' || ch == 'a')

            {

                c++;

            }

            

        }

        System.out.print("The no of A's or a's present in the string = "+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