Thursday, August 21, 2014

Names

Write a Java program for sorting a given list of names in ascending order.
___________________________________________________________

import javax.swing.JOptionPane;
import java.util.Arrays;
public class LabExercise27 {

    public static void main(String[] args) {

        String x[] = new String[5];
       
        x[0] = "Jack";
        x[1] = "Romeo";
        x[2] = "Joyce";
        x[3] = "Keith";
        x[4] = "Elieza";
       
        String all = "";
        String holder = "";
        int j = 0;
        int h = 0;
       
        Arrays.sort(x);
       
        for(int i = 0; i<5; i++){
            all = all +" "+ x[i];
        }
        JOptionPane.showMessageDialog(null, "Ascending order: "+all);
    }
}

No comments:

Post a Comment

advertisement