Menu
Question Index
...

What will be the output of the following program?

public class Recurssions {
    public int result(String input) {
        if (input == null || input.length() == 0) {
            return 0;
        }
        return result(input, 0);
    }
    public int result(String input, int count) {
        if (input.length() == 0) {
            return count;
        }
        if (input.substring(0, 1).equalsIgnoreCase("K")) {
            count = count + 1;
        }
        return result(input.substring(1), count);
    }
    public static void main(String[] args) {
        System.out.println("Output is = " + new Recurssions().result("Kakakatiya....yaKata"));
    }
}


Output is = 2
Output is = 3
Output is = 4
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