
Patrick B. answered 05/24/21
Math and computer tutor/teacher
/***************************************
//determines how many times a specified
// letter appears in the string (case sensitive)
*************************************/
class LetterFreq
{
public static void main(String args[])
{
if (args.length>=2)
{
char ch = args[0].charAt(0);
LetterFreq x = new LetterFreq();
int iReturn = x.Go(ch,args[1]);
if (iReturn!=1)
{
System.out.println( iReturn + " " + ch + "'s");
}
else
{
System.out.println(" 1 " + ch);
}
}
else
{
System.out.println (" \n\n issue the following command at the system prompt.... \n\n > java LetterFreq letter \"string\" \n\n");
System.out.println(" EX. > java LetterFreq m \"The moon is made of green cheese.\" \n\n");
System.out.println(" Output shall be 2 m's \n\n");
System.out.println(" Yes, the string MUST appear inside double quotes!!!");
}
}
public int Go(char ch, String str)
{
int iReturn=0;
for (int iLoop=0; iLoop<str.length(); iLoop++)
{
if (ch==str.charAt(iLoop))
{
iReturn++;
}
}
return(iReturn);
}
}
Harvey B.
It does not work, this is the template for the code import java.util.Scanner; public class LabProgram { public static void main(String[] args) { /* Type your code here. */ } }05/24/21