KeinHappyAuer
KeinHappyAuer

Reputation: 183

Unexpected String output

I have programmed following class in Java

public class Factorial
    {
        final String[] promotion: {"watch", "on", "youtube:", "Mickey en de stomende drol", (https://www.youtube.com/watch?v=a3leCIk2eyQ)"};
    public static void main(String[] args)
    {   
        System.out.println(shoutPromotion(promotion));
    }

    public static String shoutPromotion(String[] promotion)
    {   String result = "";
        for(int i = 1; i < promotion.length; i++)
            result += promotion[i] + " ";
        return result;
    }
}

But when I run the program I see following output in the console:

on youtube: Mickey en de stomende drol (https://www.youtube.com/watch?v=a3leCIk2eyQ)

The word watch disappeeard. How does this come?

Upvotes: 0

Views: 258

Answers (1)

Subhrajyoti Majumder
Subhrajyoti Majumder

Reputation: 41200

Array index starts with 0 not 1.

This

for(int i = 1; i < promotion.length; i++)

Change it to

for(int i = 0; i < promotion.length; i++)

Upvotes: 3

Related Questions