English

Write a Program to Input 15 Integer Elements in an Array and Sort Them in Ascending Order Using the Bubble Sort Technique.

Advertisements

Question

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

Answer in Brief
Advertisements

Solution

import java.io.*;
import java.util’*;
class AscendingOrder {
public static void main(String args[]) {
int i, j, temp;
Scanner sc = new Scanner(System.in);
int arr[] = new int[15];
System.out.println(“Enter 15 integers:”);
for (i = 0; i < = 15; i+ +) {
arr[i] = sc.nextlntO;
for(i = 0; i < 14; i++){
for(j = 0; j < 14 -i; j + +){
if(arr[j] > arr[j + 1]){
temp = arr[j];
arr[j] = arr [j + 1];
arr[j + 1] = temp;
}
}
}
System.out.println(“Elements in ascending order are::”);
for (i = 0; i < 15; i+ +) {
System.out.println(arr[i]);
}
}
}
}

shaalaa.com
  Is there an error in this question or solution?
2018-2019 (March) Set 1
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×