Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SortingArr {
- public static void FillingArr(int[] arr){
- Scanner scan = new Scanner(System.in);
- for (int i = 0; i < arr.length; i++) {
- System.out.printf("Enter element [%d]: ", i);
- arr[i] = scan.nextInt();
- }
- }
- public static void SortArr(int[] arr){
- int i, j, Buff;
- int n = arr.length;
- for(i = 0; i < n - 1 ; i++){
- for(j = 0; j < n - i - 1; j++){
- if(arr[j] > arr[j + 1]){
- Buff = arr[j];
- arr[j] = arr[j + 1];
- arr[j + 1] = Buff;
- }
- }
- }
- }
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.print("Enter the number of elements: ");
- int n = scan.nextInt();
- int[] arr = new int[n];
- FillingArr(arr);
- SortArr(arr);
- System.out.print(arr[0]);
- for (int i = 1; i < arr.length; i++) {
- System.out.print(" <= ");
- System.out.printf("%d", arr[i]);
- }
- }
- }
Add Comment
Please, Sign In to add comment