Java OCA OCP Practice Question 285

Question

Given:

public class Main {
  public static void main(String[] args) {
    String in = "1 a2 b 3 c4d 5e";
    String[] chunks = in.split(args[0]);

    System.out.println("count " + chunks.length);
    for(String s : chunks)
      System.out.print(">" + s + "<  ");
  }/*  w w w .  j a  v  a 2 s  . c  om*/
 }

And two invocations:

java Main " "
java Main "\d"

What is the result? (Choose all that apply.)

  • A. In both cases, the count will be 5
  • B. In both cases, the count will be 6
  • C. In one case, the count will be 5, and in the other case, 6
  • D. Main cannot be invoked because it will not compile
  • E. At least one of the invocations will throw an exception


B is correct.

Note

In the second case, the first token is empty.

In the first case, the delimiter is a space.

In the second case, the delimiter is any numeric digit.




PreviousNext

Related