Menu
Question Index
...

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);
    }
}


-ar--nt-antr--pe-oper-ropert-
-ar-Part--nt-antr-Pantry--pe-oper-ropert-Property-
Some other output or Compilation Error
Runtime Error

Doubts

Problems

Topic: Java String substring() method - substring In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App