Two arrays are given. It is necessary to calculate how many numbers are contained simultaneously in both the first and second arrays and output them in ascending order.
Note: If there is a number in the first array (for example, 1), and in the second array this number occurs twice (for example, an array of 5 elements: 1,2,3,4,1 ), then in this case the number 1 is 1 times in both arrays. If the number occurs several times in each array, then it is still one match.
My code is:
package shestnadcat; import java.util.Scanner; public class Shestnadcat2 { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("ΠΠ²Π΅Π΄ΠΈΡΠ΅ ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠ² ΠΏΠ΅ΡΠ²ΠΎΠ³ΠΎ ΠΌΠ°ΡΡΠΈΠ²Π°"); int b = in.nextInt(); int i; int[] a = new int[b]; for (i = 0; i < b; i++) { System.out.println("ΠΠ²Π΅Π΄ΠΈΡΠ΅ ΡΠ»Π΅ΠΌΠ΅Π½Ρ " + i); a[i] = in.nextInt(); } System.out.println("ΠΠ²Π΅Π΄ΠΈΡΠ΅ ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠ² Π²ΡΠΎΡΠΎΠ³ΠΎ ΠΌΠ°ΡΡΠΈΠ²Π°"); int d = in.nextInt(); int[] c = new int[d]; for (i = 0; i < d; i++) { System.out.println("ΠΠ²Π΅Π΄ΠΈΡΠ΅ ΡΠ»Π΅ΠΌΠ΅Π½Ρ " + i); c[i] = in.nextInt(); } int k = 0; for (i = 0; i < b; i++) { int g = a[i]; for (i = 0; i < d; i++) { if (g == c[i]) { k = +1; } } } System.out.println(k); } } The counter incorrectly displays the result.
I can not think of the output of these numbers.

Π‘ΡΡΡΡΠΈΠΊ Π½Π΅ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΠΎ Π²ΡΠ²ΠΎΠ΄ΠΈΡ ΡΠ΅Π·ΡΠ»ΡΡΠ°Ρ.- and what? - Alexey Shimanskyiin two cycles, but it should be different .... standardiandj- Alexey Shimansky{1, 1, 1}and{1, 1, 1}how many identical numbers? - andy.37