314-18 guruh talabasi Abduvohid Ergashev
Saralash dasturi
package saralash;
import java.util.Scanner;
public class saralash {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int [] array = new int[10];
for (int i=0; i<10; i++){
System.out.print("a["+(i+1)+"]=");
array[i] = in.nextInt();
}
bubbleSort(array);
printArray(array);
}
static void bubbleSort(int arr[])
{
int n = arr.length;
for (int i = 0; i < n-1; i++)
for (int j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])
{
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
static void printArray(int arr[])
{
int n = arr.length;
for (int i=0; iSystem.out.print(arr[i] + " ");
System.out.println();
}
}
Dastur natijasi:
Do'stlaringiz bilan baham: |