반응형
public static void main(String[] args) {
for(int i=1; i<=100; i++) {
System.out.print(i+" ");
}
}
}
1부터 100까지 출력
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i=1; i<=n; i++) {
System.out.print(i+" ");
}
}
}
1부터 n까지 출력
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
if (a < b) {
while (a <= b) {
System.out.print(a + " ");
a++;
}
} else if (b < a) {
while (b <= a) {
System.out.print(b + " ");
b++;
}
} else {
System.out.print(a);
}
}
}
a랑 b 입력받아서 출력 (a랑 b 중 누가 더 큰지는 모름)
a~b 까지 또는 b~a까지 출력
반응형
'공부 > 알고리즘' 카테고리의 다른 글
Do it 알고리즘 코딩테스트 (0) | 2022.06.07 |
---|---|
최소값(원하는 만큼 입력 받아서) (0) | 2021.09.12 |
백준 알고리즘 (for문) (0) | 2021.09.07 |
소수 판별(구름 알고리즘) (0) | 2021.09.07 |
알고리즘 3 (백준 알고리즘 - 입출력) (0) | 2021.09.03 |