Menu
Question Index
...

What will be the output of the following program?

public class Change {
    public static void main(String args[]) {
        change("xyz(abc)123");
    }
    private static void change(String inputString) {
        for (int i = 0; i < inputString.length(); i++) {
            if (inputString.charAt(i) == '(')
                System.out.println(getOutput(inputString, i + 1));
        }
    }
    private static String getOutput(String inputString, int count) {
        String result = "";
        for (int i = count; i < inputString.length(); i++) {
            if (inputString.charAt(i) != ')') {
                result += inputString.charAt(i);
            } else
                break;
        }
        return result;
    }
}


abc
abc123
Compilation Error
Runtime Error

Doubts

Problems

Topic: charAt() Method In Java - Java Character Extraction

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App