Results 11 to 11 of 11
-
20th Jan 2012, 04:53 AM #11Teh GFX Whore! ^.^PHP Code:
class Bubble
{
public static void main(String args[])
{
int arr1[] = {10,90,48,58}; //till here you have made 1 array called arr1 and it has 5 members namely, 10,90,48,58
for (int i=0;i<arr1.length;i++)
System.out.print(arr1[i]+ "\t"); //here, you just displayed the array using a for loop. "\t" represents a tab. Its nothing but a displaying style, it will leave a certain tabular space after displaying each member.
for(int i=0;i<(arr1.length-1);i++) //here you started the sorting loop.starting with the 1st entry of array (10)
{
for (int j=i+1;j<arr1.length;j++) //here you started second loop starting with 2nd entry of array (90)
{
if(arr1[i]>arr1[j]) //here you are comparing 1st number with 2nd number in array to sort them in ASCENDING order. If the 1st >2nd you are replacing their order in the array.
{
int x,y;
x=arr1[i];
y=arr1[j];
arr1[i] = y;
arr1[j] = x;
}
}
}
System.out.println("\n");
System.out.println("Array after sorting in ascending order");
for (int i=0;i<arr1.length;i++) { //printing the new array
System.out.print(arr1[i]+ "\t");
}
System.out.println();
}
}
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Java stinks: Turn off your Java browser plugin
By Loget in forum General DiscussionReplies: 37Last Post: 5th Sep 2012, 07:40 AM -
please help me in java
By shanshayan in forum Webmaster DiscussionReplies: 2Last Post: 10th Jan 2012, 06:48 AM -
HELP: Java countdown
By CuraHack in forum Web Development AreaReplies: 4Last Post: 9th Nov 2011, 02:42 AM -
In need of JAVA Developer
By avngr in forum Web Development AreaReplies: 2Last Post: 1st Sep 2011, 02:44 PM -
Some help need in Java programing
By bapi21 in forum Web Development AreaReplies: 1Last Post: 10th Jul 2011, 01:08 PM
themaRegister - register to forums...
Version 3.51 released. Open older version (or...