import java.util.*;
import java.io.*;
import javax.swing.*;
public class sortExample2 {
//your inputs will be here
String word1=JOptionPane.showInputDialog(null, "Input First word");
String word2=JOptionPane.showInputDialog(null, "Input Second word");
String word3=JOptionPane.showInputDialog(null, "Input Third word");
String word4=JOptionPane.showInputDialog(null, "Input Fourth word");
String [] words = { word1,word2,word3,word4};
public static void main(String args[]) {
new sortExample2().sortAndDisplay();
}
public void sortAndDisplay() {
try {
//output at the console
Writer outputDisplay =new BufferedWriter(new OutputStreamWriter(System.out));
//this here displays the sequence of your inputs
outputDisplay.write("Input sequence :\n");
for(int i=0; i < 4 ; i++) {
outputDisplay.write(words[i] + " ");
}
//a class for sorting arrays
java.util.Arrays.sort(words);
//this here displays the sorted sequence of your inputs
outputDisplay.write("\nSorted :\n");
for(int i=0; i < 4 ; i++) {
outputDisplay.write(words[i] + " ");
}
outputDisplay.flush();// Flushes this output stream and forces any buffered output bytes to be written out.
outputDisplay.close();//Closes this output stream and releases any system resources associated with this stream.
}
catch(Exception e){}
}
}
0 comments:
Post a Comment