Menu
Topics Index
...
`

Arrays and continue statement


If you need explanation Read this topic

If you need Answer Take test on this topic

Arrays and continue statement
What will be the output of the program?
public class DailyDoseC {
    public static void main(String[] args) {
        String inputString = "reactwall";
        char characters[] = inputString.toCharArray();
        System.out.print(meth(characters));
    }
    private static String meth(char[] input) {
        int totalIndex = input.length;
        int writeIndex = 1;
        if (input[0] == 'b') {    writeIndex = 0;    }
        for (int i = 1; i < totalIndex; ++i) {
            if (input[i] == 'b') {    continue;    }
            if (input[i] == 'c') {
                if (input[writeIndex - 1] == 'a') {
                    writeIndex--;
                    continue;
                }
            }
            input[writeIndex] = input[i];
            writeIndex++;
        }
        return new String(input, 0, writeIndex);
    }
}

A. reactwall
B. retwll
C. retwall
D. Compilation Error or Runtime Error.
E. None of the above.
Topic: Unknown

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.

ans c.if  checks c condition skips 'a'..
it prints retwall

Posted by Maheshwari Natarajan    2014-06-18 13:00:38


ans is c..wen we encounter the c we the writeindex value n placing it a n n decreasing the writeIndex value so a wl overide with nxt char of c

Posted by Uday Kumar    2014-06-18 13:05:02


Ans is a..while checking the condition input[i]=='c' and input[writeindex-1]=input[0] is not 'a' So the if condition is skipped the input remains as it is...the output will be reactwall

Posted by Badam Swathi    2014-06-18 13:09:34


answer c.
if loop chcks input arr with 'c' .if it true thn anotht if chcks previous char of 'c' is 'a' .
tis conditn true so 'a','c' char are skipd.
meth func return retwall

Posted by NagaRaj Nataraj    2014-06-18 14:02:56


Congratulations Maheshwari Natarajan. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-06-19 07:24:15


© meritcampus 2019

All Rights Reserved.

Open In App