Java Tutorial

 
 
 
 
import java.io.*;

class sort
{
      String str;
      int size,sortArr[];

      public void getdata()
      {
             System.out.print(\"Enter how many data you want to enter : \");
             System.out.flush();
             try{
                 BufferedReader obj=new BufferedReader(new 

InputStreamReader(System.in));
                 str=obj.readLine();
                 size=Integer.parseInt(str);
                 sortArr=new int[size];
                 for(int i=0;i<size;i++)
                   {
                       System.out.print(\"Enter element at \"+(i+1)+\"th 

position  :  \");
                       System.out.flush();
                       str=obj.readLine();
                       sortArr[i]=Integer.parseInt(str);
                   }
                }
            catch(Exception e)  {}
      }

      public void  SelSort()
      {
            System.out.println(\"=====SELECTION SORT=====\\n\");
            getdata();
            int min;
                for(int i=0;i<size;i++)
                    {
                        min=i;
                  for(int j=i+1;j<size;j++)
                      {   
                          if(min>=size)
                                  min=size;
                          if(sortArr[min]>sortArr[j])
                                    min=j;
                      }
                   int temp=sortArr[i];
                   sortArr[i]=sortArr[min];
                   sortArr[min]=temp;
                  }
            display();
        }    

    public void display()
    {
         System.out.println(\"\\nAfter Sorting\");
         for(int i=0;i<size;i++)
              System.out.println(sortArr[i]);
    }
}


class SelSort 
{
    public static void main(String args[]) 
    {
          sort ob1=new sort();
          ob1.SelSort();
    }
}

    Related Post:
  1. Develop a game application in CORBA for which the player will guess a number between 1 to 100, which will be compared to the random number generated b

  2. Program to show an example of modifying String objects

  3. Program to ask question and accept answer up to 3 attempt and display right answer if it is wrong

  4. Program to calculate the frequency for different values of C starting from 0.01 to 0.1 in steps of 0.01

  5. Program to print triangle of numbers

  6. Corba program of UDP client server application which sends the news to the client. Server takes the news from the NewsDataFile located at the server

  7. Program of FTP client and server

  8. Program to show the use of Nested If-Else Statements

  9. An applet program that displays Text at the center of the string which is passed as parameter

  10. Program to show an example of using a recursive method in a class

  11. Program to sort the contents of an array using Bubble Sort

  12. Program to show the use of Logical or Boolean Negation i.e. NOT (!)

  13. Program for calculating area of a circle on server side,when a client sends request along with given radius and then displaying result on client side

  14. Program using session tracking capability of Servlets, which displays information of current user session by HttpServletRequest object

  15. Program to represent a bank account

  16. Program to show an example of overloading constructors in a class to initialize its data members

  17. Program of an applet to illustrate BarChart

  18. Program that enabled applet that takes name of the user. Server returns back the number in uppercase clubbed with “HELLO” and display it on applet

  19. Program to show an example of Polymorphism

  20. Even number ,Prime no. ,Factorial of a number

 
 
Didn't find what you were looking for? Find more on An applet program to perform selection sort