Countdown with --
Easyjava
Learn the Concept: Unary OperatorsRead an integer N and print N, N-1, ..., down to 1 on a single line, separated by spaces, using the -- operator.
Input: one integer N.
Output: one line — the numbers from N down to 1, space-separated.
Example 1
Input
5
Output
5 4 3 2 1
- 1 <= N <= 100000
Hint 1
Start i at N and use i-- until i drops below 1.
Hint 2
Build the line in a StringBuilder, then print it trimmed.
A loop that starts high and uses i-- to step down. Collect the values with single spaces between them and trim the trailing space before printing.
Submit an attempt to unlock the solution. (Sign in first.)
Related Problems
- Sum 1..N with i++Easy · javaSolve Problem
- Negate a NumberEasy · javaSolve Problem
- Pre- vs Post-IncrementMedium · javaSolve Problem