Menu
Question Index
...

What will be the output of the following program?

public class FindSum
{
    public static void main(String[] args)
    {
        int[] a = {12, 15, 11, 13, 9, 25};
        int[] a2 = {12, 15, 11, 13, 9, 25};
        int sum = 0;
        for (int i = 0; i < a.length; i++)
        {
            if (a[i] % 3 == a2[a.length - i] % 5)
            {
                sum += i * i;
            }
        }
        System.out.println("sum = " + sum);
    }
}


sum = 5
sum = 25
sum = 30
Compilation Error
Throws ArrayIndexOutOfBoundsException

Doubts

Problems

Topic: Learn Arrays And Loops

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App