Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- public class PartitionOfArrays {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.printf("Input the number of elements : ");
- int N = Integer.parseInt(scan.nextLine());
- double[] Arr1 = new double[N];
- double[] Arr2 = new double[N];
- double[] Arr3 = new double[N];
- System.out.println();
- for (int i = 0; i <= Arr1.length - 1; i++) {
- System.out.printf("Input element [%d] of Arr1: ", i);
- Arr1[i] = Integer.parseInt(scan.nextLine());
- }
- System.out.println();
- for (int j = 0; j <= Arr2.length - 1; j++) {
- System.out.printf("Input element [%d] of Arr2: ", j);
- Arr2[j] = Integer.parseInt(scan.nextLine());
- Arr3[j] = Arr1[j] / Arr2[j];
- Arr3[j] = Arr3[j] * 100;
- Arr3[j] = Math.round(Arr3[j]);
- Arr3[j] = Arr3[j] / 100;
- }
- scan.close();
- System.out.println();
- System.out.println("Results before sort: " + Arrays.toString(Arr3));
- for (int k = 1; k < Arr3.length; k++) {
- double key = Arr3[k];
- int a = k - 1;
- while((a > -1) && (Arr3[a] > key)) {
- Arr3[a + 1] = Arr3 [a];
- a--;
- }
- Arr3[a+1] = key;
- }
- System.out.print("Results after sort: " + Arrays.toString(Arr3));
- }
- }
Add Comment
Please, Sign In to add comment