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. Application for counting factorial of a given number

  2. Program to show some properties of StringBuffer object

  3. An applet program to display sum of two number of textField

  4. File handling program to display directory contents

  5. Program, which creates a three thread. One thread display the numbers from 1 to 5, second thread display the square root of that number etc

  6. Program to represent a bank account

  7. An applet program to find maximum of three numbers using textField

  8. An applet program to draw Polygon Graph with given data

  9. File handling program to count number of characters in a file

  10. Corba program to develop a simple calculator with addition, subtraction, multiplication and division capabilities, data collection from client side

  11. Program to evaluate following investment equation V=P(1+R)^N

  12. An applet program that creates string dynamically and displays it

  13. 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

  14. Program to show the use of Logical AND Operator (&) in If Statements

  15. Program to copy the elements of an array into another array in reverse order and print them

  16. Program of date server and client

  17. Program to show the use of Increment and Decrement Operators

  18. An applet program to give demo of getDocumentBase() and getCodeBase() methods

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

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

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