Advertisement
MartyS95

Domashnopoalgoritmi17218

Jan 20th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4. import java.util.Arrays;
  5.  
  6. public class Main {
  7.     static void bubbleSort(double[] arr) {
  8.         double n = arr.length;
  9.         double temp = 0;
  10.         for (int i = 0; i < n; i++) {
  11.             for (int j = 1; j < (n - i); j++) {
  12.                 if (arr[j - 1] > arr[j]) {
  13.                     temp = arr[j - 1];
  14.                     arr[j - 1] = arr[j];
  15.                     arr[j] = temp;
  16.                 }
  17.             }
  18.         }
  19.     }
  20.  
  21.     public static void main(String[] args)
  22.     {
  23.         Scanner input = new Scanner(System.in);
  24.         int N = 0;
  25.  
  26.         System.out.printf("Input the number of elements N : ");
  27.         N = input.nextInt();
  28.  
  29.         int arr[] = new int[N];
  30.         int arr1[] = new int[N];
  31.         double arr2[] = new double[N];
  32.  
  33.         for (int z = 0; z < N; z++) {
  34.             System.out.printf("Please input the [%d] element of (Array1) : ", z);
  35.             arr[z] = input.nextInt();
  36.         }
  37.         System.out.println();
  38.         for (int w = 0; w < N; w++){
  39.             System.out.printf("Please input the [%d] element of (Array2) : ", w);
  40.             arr1[w] = input.nextInt();
  41.         }
  42.         System.out.println();
  43.         for (int s = 0; s < N; s++){
  44.             double arr2Elements = (double) arr[s] / arr1[s];
  45.             arr2[s] = (arr2Elements);
  46.         }
  47.         System.out.println("Array Before Bubble Sort : ");
  48.         System.out.println(Arrays.toString(arr2));
  49.         System.out.println();
  50.         bubbleSort(arr2);
  51.         System.out.println();
  52.         System.out.println("Array After Bubble Sort : ");
  53.         System.out.println(Arrays.toString(arr2));
  54.         System.out.println();
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement