I write a program that shows even and odd numbers in a certain interval specified by the user. And then I came across one problem, I select the interval, say, from 120 to 130, the program shows only even numbers, and odd numbers do not show
System.out.println("Четные числа"); for (; a <= b; a++) { if (a % 2 == 0) { System.out.print(a); System.out.print(","); } } It works fine to this part, then odd numbers follow and nothing is highlighted here.
System.out.println(""); System.out.println("Нечетные числа"); for (; a <= b; a++) { if (a % 2 != 0) { System.out.print(a); System.out.print(","); } } Can you tell what the problem is? And yes, if it is not difficult .. How to make the even numbers show from the end, and the odd numbers from the beginning: like this, for example: choose the interval from 10 - 30
11,13,15,17,19,21,23,25,27,29
30,28,26,24,22,20,18,16,14,12,10
аalready moreb. Get a separate variable for the loop counter:for (int i = a; i <= b; i++) { if (i % 2...2.for (int i = b; i >= a; i--) { ...- Igor