Menu
Topics Index
...
`

Party Pantry Property


If you need explanation Read this topic

If you need Answer Take test on this topic

Party Pantry Property
What will be the output of the following program?
public class Party {

    public static void main(String[] args) {
        party("Party");
        party("Pantry");
        party("Property");
    }

    private static void party(String party) {
        int length = party.length(), negative = length / 2, positive = negative;
        do {
            System.out.print(party.substring(negative, positive) + "-");
        } while (negative-- > 0 && positive++ < length);
    }
}

A. -ar--nt-antr--pe-oper-ropert-
B. -ar-Part--nt-antr-Pantry--pe-oper-ropert-Property-
C. Some other output or Compilation Error
D. Runtime Error
Topic: Java String substring() method - substring In Java

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 is b...for party length is 5 and ngtv and pstv is 2..and Pantry length is 6 and pstv n ngtv is 3 ,similr to third one,initial substring(2,2) ntg wil print,next substring(1,3),substring(0,4) so on..

Posted by Uday Kumar    2014-09-03 08:47:32


ans is b...for party length is 5 and ngtv andpstv is 2..and Pantry length is 6 and pstv n ngtv is 3 ,similr to third one,initial substring(2,2) ntg wil print,next substring(1,3),substring(0,4) so on..

Posted by Asma Mujtaba Khan    2014-09-03 08:50:54


C

Posted by Akshay Bansod    2014-09-03 09:20:51


C

Posted by Raju VarshnEy    2014-09-03 12:26:22


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

Posted by Merit Campus    2014-09-04 04:29:36


© meritcampus 2019

All Rights Reserved.

Open In App