Menu
Question Index
...

What will be the output of the following program?

public class DemoOnSubStrings {
    public static void main(String args[]) {
        String input = "hello";
        String search = "hel";
        String subString = "count";
        String result = "";
        int i = input.length();
        System.out.println(input);
        for (int j = 0; j < i; j++) {
            result = input.substring(0, j);
            result = result + subString;
            result = result + input.substring(j + search.length());
            input = result;
        }
        System.out.println(input);
    }
}


hello
cccountttttlo
hello
cccccountttttlo
hello
cccountttlo
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java String substring() method - substring 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