الأجوبة
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;
}
}
}
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال