Java program to sort ten numbers using bubble sort method

Q. Write a java program to sort ten numbers using bubble sort method.

Ans. class Bubble sort

            {

             Public static void main (string arts [] throws Io Exception

           {

            Buffered Reader in=new buffered reader (new input stream reader (system. in) ;

           Int num [];

          Num=new Int [10];

          Int I;

          String number;

          System.out.printIn ("Enter 10 numbers");

          For (I=0; i<10; i++)

         {

             Number=in. Read Line ();

             Number [I] = Integer.parseInt (number);

        }

        System.out.println ("you have entered");

        For (I=0; I<10; I++)

        {

       System.out.print (" " + num[I]+" ");

       }

     \\ Sorting beings here

    For (I=0; I <10; I++)

{

      For (J=0; J < 9-I; J++)

     {

         If (num [J] > num [J+I])

        {

           Temp= num [J];

           Num [J] = num [J+1];

            Num [J+1] = temp;

       }

  }

}

System.out.println ("array after sorting");

For (I=0; I<10; I++) \\ loop

{

       System.out.print ("  " + num [I] +" " );

} \\ end loop

} \\ end main

} \\end class

   Related Questions in Programming Languages

  • Q : Define Deadlock Deadlock : A situation

    Deadlock: A situation which occurs whenever two threads each acquires the lock to one of a set of resources which they both require.

  • Q : State Space Reduction in Java PathFinder

    State Space Reduction: JPF is a so-called explicit-state model checker, as it enumerates all visited states, and therefore suffers from the state explosion problem inherent in analyzing large programs. It also contains garbage collection, because a ty

  • Q : How is an external entity reference

    While constructing an XML DTD, how do you make an external entity reference within an attribute value?

  • Q : How XML web services integrate two

    How can XML web services integrate two legacy distributed systems, one based on Corba and one based on Java RMI?

  • Q : Describe MCP or Model Checker for C plus

    MCP: Model Checker for C++ (MCP) is an explicit-state software model checker being introduced by the Robust Software Engineering group at NASA Ames Research Center (Thompson and Brat, 2008). MCP was constructed specifically to allow programs written i

  • Q : Explain Two dimensional array Two

    Two dimensional array: A two dimensional array is a continuous memory location having similar kind of data arranged in row and column format (such as a matrix structure). D

  • Q : What is an Arithmetic expression

    Expression: It is a combination of operands and operators which generates a resultant value. Expressions contain a resulting type that affects the context in which they might be employed.

  • Q : Functions of System calls Show what are

    Show what are the different functions of System calls?

  • Q : Uses of BYTE Write a program that shows

    Write a program that shows the uses of BYTE, WORD and DWORD?

  • Q : What is Factory pattern Factory pattern

    Factory pattern: A pattern of class definition which is employed as a generator of instances of other classes. Frequently employed to form platform- or locale-particular implementations of abstract classes or interfaces. This decreases coupling betwee

©TutorsGlobe All rights reserved 2022-2023.