Guys, such a trouble. I do not understand what is the error. I need to, in the loop, at the output 2, the numbers are odd, but for some reason, the loop ends when one number is even, it closes the second number. I tried both &&, and &, I understand their difference, but it does not help. Please do not show off, and clearly explain what I'm doing wrong here. With me cookies, my mother cooks them delicious
class Test{ public static void main(String[] args){ int i,j; do { i = (int) (Math.random()*10); j = (int) (Math.random()*10); } while ((i % 2) != 0 & (j % 2) != 0); System.out.println("i = " + i + " j = " + j); } } The conclusion is (a few examples)
i = 3 j = 2 i = 6 j = 7 i = 4 j = 3
while ((i % 2) == 0 || (j % 2) == 0)- Igor(i % 2) == 0- parity,(i % 2) > 0- oddness. - Rootwarea=2n+1- the formula of odd numbers (if in the example, the random in the example is random in practice); but if you generate them separately - the probability of catching the two odd ones is higher, the method is faster - dgzargo