Topics Index

Creating method with return statement

If you need explanation Read this topic

If you need Answer Take test on this topic

Creating method with return statement
What will be the output of the following program?
public class Change {
    public static void main(String args[]) {
    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
        return result;

A. abc
B. abc123
C. Compilation Error
D. Runtime Error
Topic: charAt() Method In Java - Java Character Extraction

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

A is the answer because it prints the string between '(' and ')'

Posted by Yeshu Yeshwanthi    2013-08-05 08:44:20

Answer is A,
abc is printed as it satisfies the conditionds.

Posted by Amar Kumar Biradar    2013-08-05 08:46:06

Answer is A

Posted by Syamavidya Dhari    2013-08-05 08:48:36

C. inputString.length() should not be there.The representation  '.length()'  is not correct.The correct representation is inputString.length

Posted by Sagar Kamble    2013-08-05 11:57:05

option c
since the representation  is "inputstring.length" but here given is "inputstring.length()" it is not a function call

Posted by Sai Yaswanth    2013-08-05 11:59:23


Posted by Mani Deep    2013-08-05 12:08:28


Posted by Datta Sai Krishna    2013-08-05 12:53:25


Posted by Aruna Dantu    2013-08-05 13:37:36

Congratulations Yeshu Yeshwanthi. You are this dose winner. Please send us your mobile details and we will process the recharge asap.

Posted by Merit Campus    2013-08-06 03:44:27

thanku Merit Campus i got my recharge

Posted by Yeshu Yeshwanthi    2013-08-07 05:27:13

© meritcampus 2019

All Rights Reserved.

Open In App