Write a complete main method that does the following Takes 1
Solution
Hi Please find my code.
public class StringTest {
public static void main(String[] args) {
// if there is no command line arguments, throw exception
if(args == null){
throw new IllegalArgumentException(\"Please pass at least one command line argument\");
}
int length = args[0].length(); // length of first command line argument
String str = args[0];
int count = 0; // to keep occurence of \"ee\"
int i=0;
while(i < length){
if(str.charAt(i) == \'e\'){ // if current character is \'e
if((i+1) < length && str.charAt(i+1) == \'e\') // if next character is also \'e\',then increment count
count++;
i++;
}
i++;
}
System.out.println(\"The \\\"\"+str+\"\\\" contains \'ee\' \"+count+\" times\");
}
}
/*
Sample Output:
The \"The bees are needing keeper\" contains \'ee\' 3 times
*/
Run from command line:
StringTest \"The bees are needing keeper\"

