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!

  • one
    Maybe it makes sense to ask this question to the one who set this task before you? - DreamChild
  • This is an exercise in the java book. "Java in Examples" - Vikkingg
  • Well, it means, either the book was translated by some kind of super-brain, or its editor was drunk - DreamChild

3 answers 3

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); } 
    • Every number should be printed on the back passage ... - Barmaley

    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) + " "); }