Given the following inputs:
int x; |
Write a for loop that will print out a series of numbers starting at one less than x and ending at 0.
Sample input/outputs:
In: 7 out: 6 5 4 3 2 1 0
In: 12 out: 11 10 9 8 7 6 5 4 3 2 1 0
In: 20 out:19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 |
Solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
class Main {
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
System.out.print("In:");
int x = inp.nextInt();
//write your code below
for(int i=x-1;i>=0;i--){
System.out.print(i+" ");
}
}
}
|
반응형
'Java_beginner(Repl.it) > Auto-Graded-Course(AP CS A)' 카테고리의 다른 글
029 - Further For Loop Practice 5 (printing characters) (0) | 2019.12.07 |
---|---|
028 - Further For Loop Practice 4 (repeating X times) (0) | 2019.12.07 |
026 - Further For Loop Practice 2 (skipping by 3s) (0) | 2019.12.07 |
025 - Further For Loop Practice 1 (ascending) (0) | 2019.12.07 |
024 - For Loop 6 (optional) (0) | 2019.12.07 |