Given the following inputs:
int x; |
Write a for loop that will print out a series of numbers starting at 0 and ending at the x, exclusive.
Sample input/outputs:
In: 3 out: 0 1 2 In: 8 out: 0 1 2 3 4 5 6 7 In: 5 out: 0 1 2 3 4 |
Solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
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=0;i<x;i++) {
System.out.print(i+" ");
}
}
}
|
반응형
'Java_beginner(Repl.it) > Auto-Graded-Course(AP CS A)' 카테고리의 다른 글
027 - Further For Loop Practice 3 (descending) (0) | 2019.12.07 |
---|---|
026 - Further For Loop Practice 2 (skipping by 3s) (0) | 2019.12.07 |
024 - For Loop 6 (optional) (0) | 2019.12.07 |
023 - For Loops 5 (0) | 2019.11.30 |
022 - For Loops 4 (0) | 2019.11.30 |