Guruh talabasi Abduvohid Ergashev Saralash dasturi


Download 38.68 Kb.
Sana23.11.2020
Hajmi38.68 Kb.
#151047
Bog'liq
bubblesort


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:




Download 38.68 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling