write a method called luckyAs that takes any array of string

write a method called luckyAs() that takes any array of strings and returns the number of times the letter \"A\" appears among all the strings in the array. Fill in the method signature below, then implement the method.

Lastly , provide a set of test cases (inputs and expected outputs)



public static ______ ______ (_____)
write a method called luckyAs() that takes any array of strings and returns the number of times the letter \"A\" appears among all the strings in the array. Fill in the method signature below, then implement the method.

Lastly , provide a set of test cases (inputs and expected outputs)



public static ______ ______ (_____)
write a method called luckyAs() that takes any array of strings and returns the number of times the letter \"A\" appears among all the strings in the array. Fill in the method signature below, then implement the method.

Lastly , provide a set of test cases (inputs and expected outputs)



public static ______ ______ (_____)

Solution

// LuckyCharacter.java
// counts frequency of capital A in string Array

import java.util.Scanner;

public class LuckyCharacter
{
    public static int LuckyAs(String[] str)
    {
        char ch;
        char c =\'A\';
        int count=0;

        for(int i=0; i<str.length; i++)
        {
            for (int j = 0;j < str[i].length();j++ )
            {
                ch = str[i].charAt(j);
                if(ch == c)
                {
                    count++;
                }
            }
          
        }
        return count;
    }
   public static void main(String args[])
   {
        Scanner scan = new Scanner(System.in);
        int totalString = 3;
      
        String[] str = new String[totalString];
        str[0] = \"Aloo\";
        str[1] = \"BArAk\";
        str[2] = \"BlAck Olives\";

        System.out.println(\"The character A has occurred for \" + LuckyAs(str) + \" times\");
      
   }
}

/*
output:

The character A has occurred for 4 times

*/

 write a method called luckyAs() that takes any array of strings and returns the number of times the letter \
 write a method called luckyAs() that takes any array of strings and returns the number of times the letter \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site