Menu
Topics Index
...
`

Movie Capacity


If you need explanation Read this topic

If you need Answer Take test on this topic

Movie Capacity
What will be the output of the following program?
public class MovieCapacity {
    public static void main(String[] args) {
        String[] names1 = {"DHOOM-3","KRISH","CHENNAI EXPRESS"};
        StringBuffer names[] = new StringBuffer[3];
        for (int i = 0; i < names1.length; i++) {
            names[i] = new StringBuffer(names1[i]);
        }
        print(names, 5);
        print(names, 95);
    }
    private static void print(StringBuffer[] names, int j) {
        for (StringBuffer name : names) {
            name.ensureCapacity(j);
            System.out.print(name + " capacity- " + name.capacity() + " ");
        }
        System.out.println();
    }
}

A. DHOOM-3 capacity- 23 KRISH capacity- 21 CHENNAI EXPRESS capacity- 31 
DHOOM-3 capacity- 23 KRISH capacity- 21 CHENNAI EXPRESS capacity- 31
B. DHOOM-3 capacity- 23 KRISH capacity- 21 CHENNAI EXPRESS capacity- 31 
DHOOM-3 capacity- 95 KRISH capacity- 95 CHENNAI EXPRESS capacity- 95
C. DHOOM-3 capacity- 5 KRISH capacity- 5 CHENNAI EXPRESS capacity- 5 
DHOOM-3 capacity- 95 KRISH capacity- 95 CHENNAI EXPRESS capacity- 95
D. DHOOM-3 capacity- 23 KRISH capacity- 21 CHENNAI EXPRESS capacity- 31 
DHOOM-3 capacity- 118 KRISH capacity- 116 CHENNAI EXPRESS capacity- 126
E. Compilation Error or Runtime Error.
Topic: Java StringBuffer ensureCapacity() Method With Example

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.

answer b.
1st function her preallocatin is 5 but it is not enough .for dhoom-3 allocating size7 .hre 16 is added atomaticaly,.similarly for krish 5+16
2nd function preallocatd value enough

Posted by Ananda Kumar    2014-06-06 09:22:47


option b is correct....it wil print the capacity plus the enter number..

Posted by Vijay Kumar    2014-06-06 09:28:32


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

Posted by Merit Campus    2014-06-09 11:37:24


© meritcampus 2019

All Rights Reserved.

Open In App