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 that accepts a shopping list of items from the command line and stores them in a vector. Also provide facility to perform operation

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

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

  4. Program to compute the sum of the digits of a given integer number. eg: I/o=4 then O/p=4+3+2+1=10

  5. Program to compare Strings by compring successive corresponding characters, starting with the first character in each String

  6. Program to show the use of Logical OR Operator (|) in If Statements

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

  8. Program of inventory management and demonstrating interactive input and output

  9. Develop a simple calculator with addition, subtraction, multiplication and division capabilities, data collection from client side, executed on server

  10. Program that enabled applet calculator

  11. Program to show the use of Labeled Continue Statement

  12. Program that reads and writes random access file

  13. Write a class whose objects holds a current value and have a method to add that value, printing the new value

  14. An applet program to add two numbers where data is entered in TextField

  15. Program that takes a long sentence and a character from the client and count the occurrence of the character in the sentence at the server side

  16. Program of binary search tree

  17. Program to declare, initialize and print an array of integers

  18. Program to show the use of Comparison operator (==) for comparing Strings

  19. RMI program of count server and client

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

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