Write a program that counts from 1 to 15, prints each number and then counts as deuces in the opposite direction to 1, again typing each number.
What does "count twos" mean? Something really did not understand, good people explain!
Write a program that counts from 1 to 15, prints each number and then counts as deuces in the opposite direction to 1, again typing each number.
What does "count twos" mean? Something really did not understand, good people explain!
Like so?
for(int i=1; i <= 15; i++) System.out.println(i); for(int i=15; i>0; i-=2) { System.out.println(i); if(i > 1) System.out.println(i-1); }
Most likely like this:
for (int i = 1; i <= 15; i++){ System.out.println(i); } for (int i = 15; i >= 1; i-=2){ System.out.println(i); }
Or so:
for (int i = 1; i <= 15; i++){ System.out.println(i); } for (int i = 15; i >= 1; i-=2){ System.out.println(i + " " + (i - 1) + " "); }
Source: https://ru.stackoverflow.com/questions/215242/
All Articles