Menu
Question Index
...

What will be the output of the following program?

public class Squirrels {

    public static void main(String[] args) {
        String sounds[] = {"chittering", "chirping", "barking", "squealing"};

        int i = 0;
        int startIndex = 0;

        int endIndex = sounds[i].indexOf('t');
        do {
            int length = sounds[i].length();
            if (startIndex >= 0 && endIndex < length)
                System.out.print(sounds[i].substring(startIndex, endIndex + 1) + "#");
            else if (endIndex >= length)
                System.out.print(sounds[i].substring(startIndex, 3) + "$");
            endIndex = sounds[i].indexOf('i');
            i++;
        } while (i < sounds.length);
    }
}


ch#ch#bark#squeal#
chi#ch#ba#sque#
chit#chi#bar#squea#
Some other output or Compilation Error or Runtime Error

Doubts

Problems

Topic: Unknown

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App