Share on Google+Share on Google+

2 Answer(s)      7 years ago
Posted in : Java Interview Questions
How To Sort An Array With Out Using Sort Method ?I Want Code?
View Answers

January 3, 2010 at 1:06 AM

Here is the code in java. You can find both Ascending and Descending order code. Ascending order is commented.

public class ArraySort {

public static void main(String[] args) {
int a[] = {6,500,700,200,1000,1};
int temp=0;
/*** Descending Order***/
for(int i=0;i<a.length;i++)
for(int j=0;j<a.length;j++)
temp = a[i];
a[i] = a[j];
a[j] = temp;
/*** Ascending Order ***/
/*for(int i=0;i<a.length;i++)
for(int j=a.length-1;j>i;j--)
temp = a[i];
a[i] = a[j];
a[j] = temp;
for(int i=0;i<a.length;i++)
System.out.println("a["+i+"] = "+a[i]);


a[0] = 1000
a[1] = 700
a[2] = 500
a[3] = 200
a[4] = 6
a[5] = 1


January 4, 2010 at 10:51 AM

Hi Friend,

Try the following code:

public class SortArrayWithoutUSingMethod{
public static void sortArray(int array[], int len){
for (int i = 1; i < len; i++){
int j = i;
int tmp = array[i];
while ((j > 0) && (array[j-1] > tmp)){
array[j] = array[j-1];
array[j] = tmp;
public static void main(String a[]){
int i;
int array[]={7,2,9,6,4,8,3,1};
sortArray(array, array.length);
System.out.println("Sorted Array is: ");
for(i = 0; i <array.length; i++){




Related Tutorials/Questions & Answers:
merge sorting in arrays - Java Beginners
merge sorting in arrays  Write a program to insert string or characters to an array and apply merge sorting on this array  Hi Friend, Please visit the following link:
ARRAYS SORTING - Java Interview Questions
ARRAYS SORTING  How To Sort An Array With Out Using Sort Method ?I Want Code?  Hi, Here is the code in java. You can find both Ascending and Descending order code. Ascending order is commented. public class
Sorting String arrays in java - Java Beginners
Sorting String arrays in java  I have to make an interface... and make appropriate calls to interface to store and sort the arrays. I do not think that my sorting thusfar is correct. Can anyone help? Please help
Sorting  can any help me know which sorting algorithm java uses for sorting collection and arrays
PHP Sorting Arrays Tutorial
PHP Sorting Arrays       Sorting an array is the most useful thing you can do with an array. We...;jaguar","land rover"); echo "<b>Before sorting
sorting   write a program to arrange sorting in rows,column and diagonal
sorting  write to a program to arrange the sorting in rows, column and digonal
sorting  how to do sorting without using bubble sort,selection sort
arrays  using arrays in methods   Java use arrays in methods import java.util.*; class ArrayExample{ public static int getMaxValue(int[] arr){ int maxValue = arr[0]; for(int i=1;i < arr.length;i
Store a table with students and information (name, ID, password, crypted password, etc) in a multi-dimensional array "stud"  Arrays and Strings: Store a table with students and information (name, ID, password, crypted password
Arrays   Hi I need help with the following exercises. Exercise 1: Write a Java application in which the user is prompted for the total number of integer values to be stored in an array. Initialize the array with random values
called; 2.Create two arrays. One of them must store integer numbers... the numbers in the second array by 3; 7.Print out the contents of both arrays. 8.Swap
Sorting in Java
Sorting in Java  Sorting in Java
group by sorting
group by sorting  group by sorting of data in SQL
Sorting the array
Sorting the array  Implement a program to process votes for 5 candidates in a talent contest. The program should use a String array to hold the names... who was in 3rd, 2nd and 1st place: Hints: ? you will need to declare 2 arrays
Arrays in java
Arrays in java  what is param array in java
linear sorting
linear sorting  what is linear sorting? can any send me an example   Hi Friend, Try this: import java.util.*; class ArraySort{ public...("After Sorting: "); for(int i=0;i<arr.length;i++){ System.out.println
Sorting Program
Sorting Program  To sort 10items in alphabetical order   Arrays.sort(name of ur array)   import java.util.*; class ArrayExample{ public static void main(String[] args) { String array[]=new
sorting numbers
sorting numbers  How to sort the numbers in ascending order   import java.util.*; class SortNumbers{ public static void main(String[] args) { Scanner input=new Scanner(
sorting and storing data
sorting and storing data   sorting and storing data in UITableView
Java sorting
sorting mechanism. say about Collections.Sort() & Arrays.Sort() that uses
Sorting and Searching
Sorting and Searching  Hi i would really be thankful if someone could help me with this A program is required to ask users to rate the Java programming language using a number in the range 0 - 10. The data input is ended
Sorting an ArrayList
Sorting an ArrayList  print("code sample");Hello All, I am working on a program for school and I am having trouble with sorting my list. The numbers I receive in my output are correct, but not in ascending order as required
java arrays
java arrays  can i know how can we intilize the three dimentional arrays in java? and how can we assign thae values to that array
java arrays
java arrays  i need a java program to store student details like id,name,addr,marks,average,total..using arrays..input data using scanner class and by using class, object and constructor
Bubble Sorting in Java
Bubble Sorting in Java  Hi, What is Bubble Sorting? Guide me where to learn Bubble Sorting in Java? Thanks   Hi, Check the tutorial at Bubble Sorting in Java. Thanks
Java with Arrays
Java with Arrays  I was given the assignment to create two parallel arrays; both of size 50 (declares 50 as a constant) One is an array of strings... and store it in the arrays. The input for the problem should be provided in a text