Write a for loop that will print out the numbers starting at 1 and ending at twice the end number exclusive. Each number should be on the same line, separated by a space.
Sample inputs/outputs:
In: 5 0 1 2 3 4 5 6 7 8 9
In: 10 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
In: -5 (no output) |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
class Main {
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
System.out.print("In:");
int end = inp.nextInt();
//write your code below
if(end>0){
for(int i=0;i<end*2;i++){
System.out.print(i+" ");
}
}
else{
System.out.print("");
}
}
}
|
반응형
'Java_beginner(Repl.it) > Auto-Graded-Course(AP CS A)' 카테고리의 다른 글
022 - For Loops 4 (0) | 2019.11.30 |
---|---|
021 - For Loops 3 (0) | 2019.11.30 |
019 - For Loops 1 (0) | 2019.11.30 |
018 - Conditional Statement Practice 4 (0) | 2019.11.28 |
017 - Conditional Statement Practice 3 (0) | 2019.11.28 |