Menu
Question Index
...

What will be the output of the following program?

import java.text.*;
import java.util.*;
public class CanYouBreak {
    public static void main(String[] args) {
        String data = "Merit Campus Question";
        String find = "Cam";
        BreakIterator bi = BreakIterator.getWordInstance(Locale.US);
        bi.setText(data);
        int temp = 0;
        int i = bi.first();
        while (i != BreakIterator.DONE) {
            int k = i;
            i = bi.next();
            if (i != BreakIterator.DONE && Character.isLetterOrDigit(data.charAt(k))) {
                String word = data.substring(k, i);
                System.out.println(word + "(" + k + ", " + i + ")");
                if (word.equalsIgnoreCase(find)) {
                    temp++;
                }
            }
        }
        System.out.println(find + " = " + temp);
    }
}


Merit(0, 4)
Campus(6, 11)
Question(13, 21)
Cam = 1
Merit (0, 4)
Campus (6, 11)
Question (13, 21)
Cam = 0
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Other Advanced Topics In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App