Program to sort elements in ascending order using the bubble sort technique [ICSE 2019]

Question:

Write program to input 15 integer elements in an array and sort them in ascending order using the bubble sort technique. [ICSE 2019]

INPUT:       15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

OUTPUT:   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

CODE:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
 * Write a program to input 15 integer elements in an array and sort them in ascending order using the bubble sort technique.
 *[ICSE 2019]
 *
 * @theschoolprogrammer
 * www.theschoolprogrammer.com
 */

import java.util.*;
class AscendingOrder
{
    void main()
    {
        Scanner sc=new Scanner(System.in);
        int i,j,temp;
        int arr[]=new int[15];
        for(i=0;i<15;i++)
        {
            System.out.println("ENTER A ELEMENT");
            arr[i]=sc.nextInt();
        }
        //sorting the array arr[]
        for(i=0;i<15-1;i++)
        {
            for(j=0;j<15-1-i;j++)
            {
                if(arr[j]>arr[j+1])
                {
                    temp=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                }
            }
        }
        //printing the sorted array
        for(i=0;i<15;i++)
        {
            System.out.print(arr[i]+" ");

        }
    }
}

Comments

  1. This comment has been removed by the author.

  2. Well I went through your program it is very user friendly easy to understand and correct

    .
    .
    .
    .
    .
    PS - I checked it by compiling in my computer 😎😎

    Keep up the good work bro👍👍🤟🤟

    Replies
    1. Thank you sir for your kind words. Stay tuned to our website for updates 😊

  3. Sir/mam Please upload other questions too����

  4. nice

You are welcome to share your ideas with us in comments!!!
Emotions
Copy and paste emojis inside comment box

Full Screen Mode

Archive

Contact Form

Send

Menu