1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Don't know why selection sort isn't working?

  1. Jan 11, 2012 #1
    1. The problem statement, all variables and given/known data

    to accept 10 names and print alphabetically

    2. Relevant equations

    3. The attempt at a solution

    public class n1_s
    {void main(){
    int min,c,q;String t;
    String n[]={"b","k","a","w","e"};

    for(int i=0;i<4;i++)

    for(int j=i+1;j<5;j++)

    System.out.println(" j starting with ="+j+" n[j]="+n[j]+" n="+n+" n.compareTo(n[j]) = "+n.compareTo(n[j]));
    // int a=;
    { min=j;


    System.out.println(" exchanged s");
    System.out.println(" n["+min+"]/min ="+n[min]+" n["+i+"]="+n);
    System.out.println(" exchanged");
    System.out.println("The new array after exchange ");
    for(int f=0;f<5;f++)

    System.out.print(n[f]+" ");

    System.out.println(" ");
    System.out.println(" Result: ");
    for(int y=0;y<5;y++)



    Please point out my mistake .
    Thank you
  2. jcsd
  3. Jan 11, 2012 #2


    User Avatar
    Gold Member

    You might want to show us your output. Otherwise how do we actually know it's incorrect? (Maybe the flaw is in your alphabetical prowess. :biggrin:)

    Also, put your code within a [ CODE ] block, to preserve the indenting.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook