if your jenious rewrite this program with no errors

–3 votes
asked Jan 10 by anonymous
import.java.io.*;
import.java.util.*;
class Bubblesort
{
  public.static void main (string args[])
    throw io exception, array index bounds exception
  {
    int num;
      system.out.println ("bubble sort");
      system.out.println ("enter number of elements");
      scanner - input = new scanner (system.in);
      num = input - next.int ();
    bubble impl impl = new bubble impl (num);
      system.out.println ("enter element to sort");
    for (int i = 0; i < num, i++)
        impl.A[i] = input.next.int ());
      impl.bubble sort (num);
      impl.display (num);
  }
}
class bubble impl;
{
  int n;
  int[]A bubble impl (int[max])
  {
  A = new int[max]}
  void bubble sort (int n)
  {
    int temp;
    int swap = 0;
    for (int j = 0; j <= n - 2, j++)
      {
    if A
      [j] < A[j + 1]
      {
        temp = A[j];
        A[j] = A[j + 1];
        A[j + 1] = temp;
        systemm.out.println ("array element at" + s + position + A[J]);
        system.out.println ("array element at" + (J + 1) + position +
                A[j + 1]) swap++;
      }
      }
  }
  system.out.println ("no.of interchanges are" + (swap));
}

void display (intn)
{
  system.out.println ("/n sorted list is");
  for (int i = 0; i < n; i++)
    system.out.println ("position" + A[j]);
}
}

1 Answer

+1 vote
answered Jan 11 by (2,690 points)
here:

https://onlinegdb.com/HJ2IM_wxI

When you're doing bubble sort you need to do swaps repeatedly until there are no things left to swap ( = array is sorted). Therefore I've added it to your program.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...