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

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

Edited 5 Years Ago by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

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)

Edited 5 Years Ago by peter_budo: n/a

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)

This article has been dead for over six months. Start a new discussion instead.