java – nested loops (call forward and backward sequence)


Hello people. tell a newbie on nested loops. I need to make a sequence from 1 to 9 with the sequence from 9 to 1 inserted between them. I try to do it this way, but something does not work.

 int i, j;
 for (i=1, j=9; i<=9, j=>1; i++, j--){
       System.out.printf(%d i);
       System.out.printf(%d j);

there were more options: for with a label like loop, break-continue, switch-case. they need to be looped in and the external to be called from the internal, and vice versa. but the simplest way is, as I suggest, probably .. how to loop the switch-case? it should turn out: 192837465564738291 without an array) and just loops.


As I understand it, you come here with educational problems, it is better to solve them yourself (however crookedly) and come with problems in the solution. Be clear about what you want to get, what you get, and what you think doesn't work.

You're cheating now, it won't do you any good.

For this task, I will describe the algorithm, and you will code it yourself:

1. Первый цикл от 1 до 10 (10 не включается)
1.1 Вывести счетчик цикла
1.2 вывести 10 минус счетчик цикла

all. the number 10 can be moved into a separate variable, if desired

for with a label like loop, break-continue

try to use them only in extreme cases, they do not really fit into the code (legacy of this goto)

Scroll to Top