There is a task

Create two arrays of 10 whole random numbers from the segment [1; 9] and a third array of 10 real numbers. Each element with the i-th index of the third array must be equal to the ratio of the element from the first array with the i-th index to the element from the second array with the i-th index. Print all three arrays on the screen (each on a separate line), then print the number of whole elements in the third array.

public class Main { public static void main(String[] args) { int[] massivOne = new int[10]; int[] massivTwo = new int[10]; double[] massivThree = new double[10]; for (int i = 0; i < 10; i++){ massivOne[i] = (int)(Math.random()*8 +1); massivTwo[i] = (int)(Math.random()*8 +1); massivThree[i]= massivOne[i]/massivTwo[i]; } for (int i = 0; i < 10; i++){ System.out.print(massivOne[i] + " "); } System.out.println(); for (int i = 0; i < 10; i++){ System.out.print(massivTwo[i] + " "); } System.out.println(); for (int i = 0; i < 10; i++){ System.out.print(massivThree[i] + " "); } System.out.println(); } 

}

I can not figure out how to properly check for integrity? and is the rest of the solution correct? Thanks in advance for the hint :)

    1 answer 1

     package com.sevak_avet.Test; import java.util.Random; public class Test { public static void main(String[] args) { int[] a = new int[10]; int[] b = new int[10]; double[] c = new double[10]; Random r = new Random(); int wholeCount = 0; for (int i = 0; i < 10; ++i) { a[i] = 1 + r.nextInt(9); b[i] = 1 + r.nextInt(9); c[i] = a[i] / (double) b[i]; if (c[i] == (int) c[i]) { ++wholeCount; } } for (int number : a) { System.out.printf("%d ", number); } System.out.println(); for (int number : b) { System.out.printf("%d ", number); } System.out.println(); for (double number : c) { if (number == (int) number) { System.out.printf("(%.2f) ", number); } else { System.out.printf("%.2f ", number); } } System.out.println(); System.out.println("Count: " + wholeCount); } 

    }