public static void main (String args[]) {
String [] array=new String [10];
int nItems=array.length;
int i,j;
for (i=0; i<array.length; i++){
String e=JOptionPane.showInputDialog ("Enter a string value:");
array[i]=e;
}
String search=JOptionPane.showInputDialog ("Enter string search:");
for (j=0; j<nItems; j++)
if (search.compareTo(array[j])>0)
break;
if (j==nItems)
JOptionPane.showMessageDialog (null, search+" not found!", "Case Study", JOptionPane.ERROR_MESSAGE);
else
JOptionPane.showMessageDialog (null, "Found "+search, "Case Study",JOptionPane.INFORMATION_MESSAGE);
for(i=1 ; i<nItems ; i++){
for(j=0 ; j<i ; j++){
if(array[i].compareTo(array[j])<0){
String temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
String output="Array of characters in ascending order:"+"\n"+"\n";
for(i=0 ; i<nItems ; i++)
output+=" "+array[i]+" ";
JTextArea outputArea= new JTextArea ();
outputArea.setText(output);
JOptionPane.showMessageDialog (null, outputArea, "Case Study", JOptionPane.PLAIN_MESSAGE);
for(i=1 ; i<nItems ; i++){
for(j=0 ; j<i ; j++){
if(array[i].compareTo(array[j])>0){
String temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
String output2="Array of characters in descending order:"+"\n"+"\n";
for(i=0 ; i<nItems ; i++)
output2+=" "+array[i]+" ";
JTextArea outputArea2= new JTextArea ();
outputArea2.setText(output2);
JOptionPane.showMessageDialog (null, outputArea2, "Case Study", JOptionPane.PLAIN_MESSAGE);
String del=JOptionPane.showInputDialog ("Enter string to delete:");
JOptionPane.showMessageDialog (null,"\n"+"Delete element "+del,"Case Study", JOptionPane.INFORMATION_MESSAGE);
for (j=0; j<nItems; j++)
if (del.compareTo(array[j])>0)
break;
for (int k=j; k<nItems-1; k++)
array[j]=array[k+1];
nItems--;
String output3="Array after deletion of element "+del;
for (j = 0; j <nItems; j ++)
output3 +="\n"+array[j]+ " ";
JTextArea outputArea3= new JTextArea ();
outputArea3.setText(output3);
JOptionPane.showMessageDialog (null, outputArea3, "Case Study", JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
}
as you can see... its supposed to make you enter 10 strings... then you search for an item... then it sorts the elements... then you delete an item....
thank you very, very much!!!!


Sign In
Create Account


Back to top










