# data[].attributes.body
int[] arr={12, 34, 23, 2, 4, 56, 80, 34, 45, 90};

int length = arr.length;
int temp = 0;

for(int i=0; i <  length; i++){
for(int n = 1; n < (length - i); n++){
if(arr[n-1] > arr[n]){
temp = arr[n-1];
arr[n-1] = arr[n];
arr[n] = temp;

}
}
}for(int i=0; i < arr.length; i++){
System.out.print(arr[i] + " ");

# data[].attributes.body
package week6;

public class bubblesort {

public static void main(String[] args) {
int[] arr={12,34,23,2,4,56,80,34,45,90};

int j;
boolean flag = true;   // set flag to true to begin first pass
int temp=0;  //holding variable

while ( flag )

{
flag= false;    //set flag to false awaiting a possible swap
for( j=0;  j < arr.length -1;  j++ )
{
if ( arr[ j ] < arr[j+1] )   // change to > for ascending sort
{
temp = arr[ j ];                //swap elements
arr[ j ] = arr[ j+1 ];
arr[ j+1 ] = temp;
flag = true;              //shows a swap occurred
}
}
}

for (int i = 0; i < arr.length; i ++)
{
System.out.println (arr[i]);
}

}

}

# data[].attributes.body
int[] Integers = {4,3,7,14,1,51,11,93,2,71};    // Initialize Array of 10 integers

boolean swap = true; // Set swap to true otherwise the algorithm may not run

int temp;

do{

swap=false;

for(int i=0; i<Integers.length-1; i++){

if(Integers[i]>Integers[i+1]){ // Compare current and next value

temp = Integers[i+1];  // If the value is larger than the next value, swap them

Integers[i+1] = Integers[i];

Integers[i] = temp;

swap = true; // Makes sure the computer knows a swap has occured

}

}

}while(swap==true);

for(int i=0; i<Integers.length; i++){ // Output the sorted array values in ascending order

System.out.println(Integers[i]);

}
}

# data[].attributes.body
public class bubbleSort {

public static void main(String[] args) {
// TODO Auto-generated method stub
int[] nums ={12,55,23,87,11,5};
System.out.println(Sort(nums[]));
}

public int Sort(int[] nums){
boolean flag=true;
while(flag){
flag = false;
for(int i = 0;i<nums.length;i++){
if(i<nums.length-1&&nums[i]>nums[i+1]){
for(int j = i; j<nums.length;j++){
int temp = nums[j];
nums[i]=nums[j];
nums[j]=temp;
flag=true;
}
}
}
}

return nums;
}
}

# data[].attributes.body
int[] sorting={12,34,23,2,4,56,80,34,45,90};

int holdspace=0;
int length=sorting.length;
for(int i: sorting){

for(int x=1;x<length;x++){

if(sorting[x-1]>sorting[x]){
holdspace=sorting[x-1];
sorting[x-1]=sorting[x];
sorting[x]=holdspace;

}
}
}

for(int i=0;i<length;i++){
System.out.println(sorting[i]);
}

# data[].attributes.body
int[] numbers=new int [10];
numbers[0]=12;
numbers[1]= 34;
numbers[2]=23;
numbers[3]=2;
numbers[4]=4;
numbers[5]=56;
numbers[6]=80;
numbers[7]=34;
numbers[8]=45;
numbers[9]=90;

int n=numbers.length;
int s=0;
for(int i=0;i<10; i++) {
for (int j=1; j<(n-i); j++) {
if (numbers[j] < numbers[j-1]) {
s=numbers[j];
numbers[j]=numbers[j+1];
numbers[j+1]=s;
}
}
System.out.println("The sorted numbers are" + " " +(numbers[i]));
}
}
}