Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- import java.util.Arrays;
- public class Main {
- static void bubbleSort(double[] arr) {
- double n = arr.length;
- double temp = 0;
- for (int i = 0; i < n; i++) {
- for (int j = 1; j < (n - i); j++) {
- if (arr[j - 1] > arr[j]) {
- temp = arr[j - 1];
- arr[j - 1] = arr[j];
- arr[j] = temp;
- }
- }
- }
- }
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- int N = 0;
- System.out.printf("Input the number of elements N : ");
- N = input.nextInt();
- int arr[] = new int[N];
- int arr1[] = new int[N];
- double arr2[] = new double[N];
- for (int z = 0; z < N; z++) {
- System.out.printf("Please input the [%d] element of (Array1) : ", z);
- arr[z] = input.nextInt();
- }
- System.out.println();
- for (int w = 0; w < N; w++){
- System.out.printf("Please input the [%d] element of (Array2) : ", w);
- arr1[w] = input.nextInt();
- }
- System.out.println();
- for (int s = 0; s < N; s++){
- double arr2Elements = (double) arr[s] / arr1[s];
- arr2[s] = (arr2Elements);
- }
- System.out.println("Array Before Bubble Sort : ");
- System.out.println(Arrays.toString(arr2));
- System.out.println();
- bubbleSort(arr2);
- System.out.println();
- System.out.println("Array After Bubble Sort : ");
- System.out.println(Arrays.toString(arr2));
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement