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. An applet program to display alternate filled and empty circle that to in row and column format

  2. Program to show the use of Conditional (Ternary) Operator

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

  4. Program of Floyds Triangle

  5. Program to read the table elements into a two-dimensional array temperature

  6. Write a program for restaurant

  7. Program of writing Bytes to a File

  8. Program using Switch case to compute the net amount to be paid by a customer

  9. Program of date server and client

  10. Program which creates an Array of character. Make one function with one argument as a character and that function throw a user defined exception

  11. Program to show an example of using a Non-Static Nested Class

  12. Program to show an example of extraction of characters from a StringBuffer objects

  13. Word list program that reads a text file and makes an alphabetical list of all the words in that file. The list of words is output to another file

  14. Program to show an example of extracting subStrings from a String

  15. Dialog Boxes

  16. Program to show an example of Concatination of Strings

  17. Program sets up a String variable containing a paragraph of text of your choice. Extract the words from the text and sort them into alphabetical order

  18. Program of insertion sort

  19. Program to show the use of Switch Statement for the same statement for several different case labels

  20. program which takes a long sentence from the client passes to the server,server separates out each word and sends them back to client in reverse order

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