Given the following inputs:
int x; |
Write a for loop that will print out a series of numbers starting at 0 and ending before x, skipping 3 each time (excluding x).
Sample input/outputs:
In: 7 out: 0 3 6
In: 12 out: 0 3 6 9
In: 20 out: 0 3 6 9 12 15 18 |
HINT: You'll want to change the increment part of the for loop!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
class Bakjoon {
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+=3) {
System.out.print(i+" ");
}
}
}
|
반응형
'Java_beginner(Repl.it) > Auto-Graded-Course(AP CS A)' 카테고리의 다른 글
028 - Further For Loop Practice 4 (repeating X times) (0) | 2019.12.07 |
---|---|
027 - Further For Loop Practice 3 (descending) (0) | 2019.12.07 |
025 - Further For Loop Practice 1 (ascending) (0) | 2019.12.07 |
024 - For Loop 6 (optional) (0) | 2019.12.07 |
023 - For Loops 5 (0) | 2019.11.30 |