Java Code:
import java.util.*;
public class a_bubblesort {
	
	public static void main(String[]args)
	{
		String[] array={"Hello", "Before", "After", "Cool"};
		int[] array2={6,3,8,1,4};
		int[] array3;
		
		
		array3=bubbleSort(array2);
		System.out.println();
		for(int i=0; i<array3.length; i++)
		{
			
			System.out.println(array3[i]);
		}
	}
	
	public static int[] bubbleSort(int[] array)
	{
	
		int next;
		int next_pos;
		for(int i=0; i<array.length-1; i++)
		{
			next=array[i+1];
			next_pos=i+1;


			if(array[i]>next)
			{
				System.out.print(array[i]+" is greater to ");
				System.out.println(next);
				for(int i2=next_pos-1; i2>=0; i2--)
				{
					if(i2==0)
					{
						array[next_pos]=array[0];
						array[next_pos-1]=next;
					}
					if(i2>0)
					{
						if(next>array[i2-1])
						{
							array[next_pos]=array[i2];
							array[i2]=next;
						}
					}
					
					
				}
				
			}
			else
			{
				System.out.print(array[i]+" is less than ");
				System.out.println(next);
			}


						
		}
		
		return array;
	}
}
basically this function should examine each pair of cells so it examines 0&1, determines which is larger and moves it, then examines 1&2, and so on. However, For some reason my output reveals two three's and it isn't in order. Is something wrong with my logic?

output:
6 is greater to 3
6 is less than 8
8 is greater to 1
3 is less than 4


3
6
1
3
4