Please help me with my homework!:) Here's the instruction, Write a java program that accepts ten letters(small letters), then it will sort them alphabetically, using one dimension array.
Please help, I'm dead if I won't get this correct.
Tnx

and here is what we ask you TO-DO first

Here is the short code that I've made last night

import javx.swing.*;
public class Sort{
  public static void main(String[] args){
     char[]letter = new char[10];

     for(i = 0; i < 10; i++){
     buffer[i] = 'a';
     JOptionPane.showInputDialog(null, "Enter a String: ");
     }
  }
}

well this program accepts ten letters but when you also input numbers it accepts it also but the real problem is I don't know how to sort it out.
Please help me!
:)
tnx

It doesn't accept anything, array values that you been supposed to get from user? You just hard coded buffer[i] = 'a'; . Also reconsider if you wish to use JOptionPane (as at current time is just showing pop-ups and not storing values)

One way would be to go through the array and compare two items in it and swap them if needed. Look up how to use .compareTo and swap

well how do we sort char variables anyway? without using any package

Well you do it by buffer[i].compareTo(buffer[i+1]) (in API) that would be normally used in bubble sort or any other. For fast painless solution I would go with Arrays.sort(buffer) (in API)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.