Menu
Question Index
...

What will be the order of the array elements at the end of the program?

public class SortArray
{
    public static void main(String[] args)
    {
        int[] array = {12, 15, 11, 13, 9, 25};
        for (int i = 0; i < array.length - 1; i++)
        {
            if (array[i] > array[i + 1])
            {
                int temp = array[i];
                array[i] = array[i + 1];
                array[i + 1] = temp;
            }
        }
    }
}


12, 15, 11, 13, 9, 25
12, 11, 13, 9, 15, 25
9, 11, 12, 13, 15, 25,
Throws ArrayIndexOutOfBoundsException
Compilation Error

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