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. Program to show the use of Switch Statement

  2. Program to show the use of If-Else Statement

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

  4. Program to show the use of If Statement

  5. Application which takes your marks of six subjects from the client side and displays the percentage that you have obtained

  6. Program to display triangle of numbers

  7. Program to show the use of Conditional AND Operator (&&) in If Statements

  8. An applet program to display Horizontal Color Bar

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

  10. Program to show the use of operator (&gt;&gt;) Shift Right, propagating the sign bit from the left

  11. An applet program to display moving banner

  12. Program to show an example of using constructors in a class to initialize its data members

  13. Program to read the ballots and count the votes cast for each candidate using an array variable count

  14. Program to find the number of and sum of all integers greater than 100 and less than 200 that are divisible by 7

  15. Develop a RMI based application for addition of two complex numbers

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

  17. Program of creating a file using text fields in windows

  18. Corba program to Write a Echo server and client with UDP server and client

  19. Program to show some properties of StringBuffer object

  20. Develop a CORBA application that takes a string from client and returns whether it is palindrome

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