Java OCA OCP Practice Question 2123

Question

Choose the correct option based on this program:.

public class Main {
     private static boolean removeVowels(int c) {
             switch(c) {
             case 'a': case 'e': case 'i': case 'o': case 'u': return true;
             }//from   www  .j  a va2  s  . c om
             return false;
     }
     public static void main(String []args) {
             "avada kedavra".chars()
                     .filter(Main::removeVovels)
                     .forEach(ch -> System.out.printf("%c", ch));
     }
}
a.  this program results in a compiler error
B.  this program prints: "aaaeaa"
C.  this program prints: "vd kdvr"
d.  this program prints: "avada kedavra"
e.  this program crashes by throwing a java.util.IllegalFormatConversionException
F.  this program crashes by throwing a java.lang.IllegalStateException


B.

Note

Because the Main::removeVowels returns true when there is a vowel passed, only those characters are retained in the stream by the filter method.

hence, this program prints aaaeaa.




PreviousNext

Related