Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
+2 votes
24.0k views
in Computer by (250 points)
closed by
Write a program to input and store the weight of 10 people. Sort and display them in descending order using the bubble sort technique.

2 Answers

+1 vote
by (250 points)
edited by
 
Best answer

import java.util.Scanner;

public class Arrays 

{

 public static void main(String[] args) 

{

  int arr[];

  int size;

  Scanner ip = new Scanner(System.in);

  System.out.print("Enter the size of an Array: ");

  size = ip.nextInt();

  arr = new int[10];

  for (int i = 0; i < 10; i++) {

   System.out.println("Enter weight[" + i + "]: ");

   arr[i] = ip.nextInt();

  }

for (int i = 0; i < 10; i++) {

   for (int j = 0; j < 10 - 1; j++) {

    if (arr[j] < arr[j + 1]) {

     int temp = arr[j];

     arr[j] = arr[j + 1];

     arr[j + 1] = temp;

    }

   }

  }

        System.out.println();

  System.out.println("After sorting the weight of ten people, \nIn descending order, the array elements are: ");

  display(arr);

  ip.close();

 }

 private static void display(int[] arr) {

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

   System.out.print(arr[i] + " ");

  }

 }

}

Output of the above program

0 votes
by (46.0k points)

Import Java.Io.*;

public class sortData

public static void main() throws IOException

{

by (250 points)
It's the selection sort technique , please give the answer using bubble sort technique

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...