3 - 제어문
2023. 1. 3. 21:48ㆍ프로그래밍 언어/JAVA
if 문법
if(조건식) {
실행내용;
}
else if(조건식) {
실행내용;
} else {
실행내용;
}
public class Main {
public static void main(String[] args) {
int x = 55;
if(50 <= x && x <= 60) {
System.out.println("승리");
} else {
System.out.println("패배");
}
}
}
반복문(while, do~while, for)
while(조건식) {
실행코드;
}
-> 반복문을 사용하는 이유는 어떤 작업을 n번 반복하기 위해서다.
for문
for(초기식; 조건식; 증감식) {
실행내용;}
public class Main {
public static void main(String[] args) {
for(int i = 1; i <= 3; i++) {
System.out.println(i);
}
}
}
'프로그래밍 언어 > JAVA' 카테고리의 다른 글
배열 - 얕은 복사/ 깊은 복사 (0) | 2023.01.10 |
---|---|
Scanner - next() (0) | 2023.01.06 |
Scanner - nextLine(), nextInt() 비교 (0) | 2023.01.06 |
2- 연산자(Operator) (0) | 2023.01.02 |
1 - 변수(variable) (0) | 2023.01.02 |