Q:

examples of bubble sort algorithm in java

0

give me examples of bubble sort algorithm in java programming language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

calculate the summation of rows, and average of rows:

int[][] numbers = { {3,6,12},
				    {1,3,5,7,9},
				    {7,15},
				    {5,4,9,13,12,7,6},
				    {8,9,11,12} };
		int total;
		int[] avg = new int[5];

		for (int i = 0; i < numbers.length; i++)
		{
			total = 0;
			for(int j = 0; j < numbers[i].length; j++)
				total += numbers[i][j]; 
			avg[i] = total / numbers[i].length;
		}
		sort(avg);
		System.out.println();
		for (int i = 0; i < avg.length; i++)
		{
			System.out.print(avg[i] + " ");
		}
	}
		

	
	//bubble sort:
		public static void sort(int[] array)
		{
			int temp;
				
			for (int i = 0; i < array.length; i++)
			{
				for (int j = i + 1; j < array.length; j++)
				{
					if (array[i] > array[j] )
					{
						temp = array[i];
						array[i] = array[j];	
						array[j] = temp;
					}
				} 	
			}
		}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now