Question Index

What will be the output of the following program?

public class FindSubString
    public static void main(String[] args)
        String searchString = "This is the string in which you have to search for a gnirtsbus.";
        String substring = "substring";
        boolean found = false;
        int searchUpto = searchString.length() - substring.length();
        substring = new StringBuffer(substring).reverse().toString();
            for (int i = 0; i <= searchUpto; i++)
                int length = substring.length();
                int j = i;
                int k = 0;
                while (length-- != 0)
                    if(searchString.charAt(j++) != substring.charAt(k++))
                        continue lable;
                found = true;
                break lable;
        if (found)
            System.out.println("Substring searched successfully.");
            System.out.println("Sorry, substring not found.");

Substring searched successfully.
Sorry, substring not found.
Compilation Error
Runtime Error



Topic: Java StringBuffer, reverse() - Reverse A String In Java

Read this topic
Take test on this topic

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App