Results 1 to 4 of 4

Thread: Sort array version 2

  1. #1
    Administrator asylu3's Avatar
    Join Date
    Jun 2000
    Location
    Thailand
    Posts
    3,557


    Sort array version 2

    [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]

  2. #2
    Junior Member
    Join Date
    Sep 2002
    Location
    United States
    Posts
    9


    Re: Sort array version 2

    ถามหน่อยนึง
    เห็นมานานละ
    แต่ไม่เข้าใจว่าเอาไปทำอะไร
    ??? ??? ???

  3. #3
    Administrator asylu3's Avatar
    Join Date
    Jun 2000
    Location
    Thailand
    Posts
    3,557


    Re: Sort array version 2

    Let's copy it 'n paste in editplus, then try to compile to see the output. If it not clear I will explain more later. Thank for ur interest.

  4. #4
    Junior Member
    Join Date
    Sep 2002
    Location
    United States
    Posts
    9


    Re: Sort array version 2

    ขอบพระทัย
    ทั่นปะทานปะเทด

Similar Threads

  1. Replies: 0
    Last Post: 16-09-2004, 02:11 AM
  2. standard sort array
    By asylu3 in forum Java
    Replies: 0
    Last Post: 19-04-2004, 02:15 PM
  3. Replies: 0
    Last Post: 25-11-2003, 07:55 PM
  4. Replies: 0
    Last Post: 19-08-2003, 11:48 PM
  5. Replies: 0
    Last Post: 15-07-2003, 05:31 AM

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •