[src]
import javax.swing.*;
public class Sortarray_22
{
public static void main(String[] args)
{
int Begin,End=0;
int tmp=0;
int size=4;
int[] array = new int [size];
String msg="";
JLabel out = new JLabel();
JFrame frame=new JFrame("test");
frame.getContentPane().add(out);
frame.setSize(350,100);
frame.show();
for (int i=0;i<size;i++ )
{
array[i]=Integer.parseInt(JOptionPane.showInputDialog(null,"give me at interger at you want sort : "));
System.out.print(array[i]+"n");
if (array[i]==-1)
{
break ;
}
}
Begin= Integer.parseInt(JOptionPane.showInputDialog(null,"Begin position : "))-1;
End = Integer.parseInt(JOptionPane.showInputDialog(null,"End position : "))-1;
if (End<Begin)
{
JOptionPane.showMessageDialog(null,"Invalid input");
}
else
for ( int i= Begin;i <= End;i++)
{
for (int j = i;j <= End;j++)
{
if (array[i] > array[j])
{
tmp = array[i];
array[i] = array[j];
array[j] = tmp;
}
}
}
msg="The sorted array from position "+Begin+" to " +End+" is [" ;
for (int i = Begin;i <= End;i++)
{
msg+=array[i]+"t";
}
out.setText (msg+"]");
}
}
[/src]


Reply With Quote
