Menu
Question Index
...

What will be the output of the following program?

import java.util.*;

public class Printed
{
    public static void main(String a[])
    {
        String result = frontTimes("Chocolate", 5);
        System.out.println(result);
    }
    public static String frontTimes(String str, int n)
    {
        String result = "";
        if (str.length() > 3)
        {
            for (int i = 0; i < n; i++)
            {
                result += str.substring(0, 3);
            }
        }
        else
        {
            for (int i = 0; i < n; i++)
            {
                result += str;
            }
        }
        return result;
    }
}


ChocoChocoChoco
ChoChoChoChoCho
ChocoChocoChocoChocoChoco
ChoChoChoChoChoCho
Compilation Error or 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