You need an algorithm that must:
Print the characters of a String, in index order
Skip all instances of the character ‘a’ that appear in the String
Given:
2. public void foo (String s) {
3. // insert code here
4. }
Which two, inserted independently at line 3, correctly implement the algorithm? (Choose two.)
A.
int i = 0;
while (i < s.length()) {
if (s.charAt(i) != ‘a’) {
System.out.print(i);
}
i++;
}
B.
for(char c:s) {
if (c != ‘a’) System.out.print(c);
}
C.
for(int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c != ‘a’) System.out.print(c);
}
D.
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != ‘a’) System.out.print(i);
}
E.
int i = 0;
while (i < s.length()) {
if (s.charAt(i) != ‘a’) {
System.out.print(s.charAt(i));
}
i++;
}