What is the result?

Given:


What is the result?
A. Marrown
String out of limits
JesOran
B. Marrown
String out of limits
Array out of limits
C. Marrown
String out of limits
D. Marrown
NanRed
JesOran

Download Printable PDF. VALID exam to help you PASS.

0 thoughts on “What is the result?

  1. Option A.

    class Test {

    public static void main(String[] args) {

    String names[] = new String[3];
    names[0] = “Mary Brown”;
    names[1] = “Nancy Red”;
    names[2] = “Jessy Orange”;

    try {
    for (String n : names) {
    try {
    String pwd = n.substring(0, 3) + n.substring(6, 10);
    System.out.println(pwd);
    }
    catch (StringIndexOutOfBoundsException sie) {
    System.out.println(“string out of limits”);
    }
    }
    }
    catch (ArrayIndexOutOfBoundsException e) {
    System.out.println(“array out of limits”);
    }
    }
    }

    Output:
    Marrown
    string out of limits
    JesOran

    Explanation:
    In method substring(int beginIndex, int endIndex) “beginIndex” is inclusive, “endIndex” is exclusive.
    https://beginnersbook.com/2013/12/java-string-substring-method-example/

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.