# Thread: ascending order using array rush

1. Member
Join Date
Jan 2011
Posts
1
Rep Power
0

## ascending order using array rush

nid some help we use basic code like int arr []=new arr[5].... like that....

import java.io.*;
public class aw{
public static void main(String args[])throws IOException{
BufferedReader bsit=new BufferedReader (new InputStreamReader (System.in));

int[]array = new int[10];
int x,y=0;

for (x = 0; x < 10; x++){
System.out.print("Enter a number: ");
array[x] = Integer.parseInt(bsit.readLine());

please continue this code......

2. Senior Member
Join Date
Dec 2010
Posts
100
Rep Power
0
Hey - you have to be more clear when you post a question for anyone to be able to help you. From your post subject, I am assuming you are looking to sort an array in ascending order.

The Arrays class has a method sort() you might want to use in your case.

The code will look like:

Arrays.sort(arrays);

Hope that helps.

Best,

3. Senior Member
Join Date
Dec 2010
Posts
165
Rep Power
6
Compile, run and debug the code as you wish. Understand what the program is doing and insert your own explanation as comments.
Java Code:
```import java.io.*;
public class IntegerSort {
public static void main(String[] args) throws IOException{
BufferedReader bsit=new BufferedReader (new InputStreamReader (System.in));
int[] array = new int[10];
int x,y=0;
for (x = 0; x < 10; x++){
System.out.print("Enter a number: ");
array[x] = Integer.parseInt(bsit.readLine());
}
int[] result = sort( array );
for(int i=0; i< result.length; i++){
System.out.println( result[i] );
}
}

public static int[] sort(int[] a) {
int tmp;
int smallest;
for (int i = 0; i < a.length; i++) {
smallest = i;
for (int j = i + 1; j < a.length; j++) {
// ascending order
if(  a[j] < a[smallest] ) {
smallest = j;
}
}
swap( a , i, smallest);
}
return a;
}
public static void swap( int[] array, int a, int b ){
int tmp;
tmp = array[a];
array[a] = array[b];
array[b] = tmp;
}
}```
Last edited by JavaHater; 01-03-2011 at 05:26 AM.

#### Posting Permissions

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