05-18 01:37
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- X윈도우
- 백준
- dbms
- Physical Scheme
- Java
- 셀레니움
- 자바
- literal
- Operator
- Binary Search
- 리눅스 마스터 1급
- Unity
- descriptive statistics
- 리눅스
- OOP
- Inheritance
- python
- selenium
- systemd
- BFS
- Mac
- Class
- Polymolphism
- Reference Type
- preprocessing
- External Scheme
- Entity Set
- Entity
- X.org
- spring
Archives
- Today
- Total
Byeol Lo
조건문과 반복문 본문
조건문 : 조건에 대해 수행되는 중괄호 문장들
반복문 : 조건에 따라 반복되는 중괄호 문장들
논리식을 적절히 활용하여 컴퓨터에게 연산 과정들을 조작해 수행할 수 있다.
if문
//유형 1
if (조건) {
}
//유형 2
if (조건) {
} else {
}
//유형 3
if (조건) {
} else if {
} else {
}
for 문에는 특이한 for문이 있는데, 배열(순서가 있는 인스턴스)를 하나씩 받아와서 반복시키는 문법이 있다. python의 for ~ in 문과 같다.
public class Main {
public static void main(String[] args) {
char[] array = {'a', 'b', 'c', 'd', 'e'};
for(char i:array) {
System.out.println(i);
}
}
}
switch 문
switch(num) {
case 1:
break;
case 2:
break;
//...
default:
break;
}
반복문
for 문
int sum = 0;
for (int i=0; i<=100; i++) {
sum = sum + i;
}
while 문
while(조건식) {
// 실행문
}
do-while문
do {
} while (조건);
반복문은 무한반복을 막기 위해 예약어 break를 써서 빠져 나올 수 있다. 이때 이중 반복문이라면 break가 있는 문을 빠져나가고 밖의 반복문은 빠져나가지 않는다.
더보기
예약어 Continue
반복문을 실행하는 도중에 continue를 만나면 즉시 다음 실행문을 정지하고 다음 반복문을 바로 시작시킨다.
public class Main {
public static void main(String[] args) {
for(int i=0; i<10; i++) {
if(i==7) {
continue;
} else {
System.out.println(i);
}
}
}
}
'Programming Language > Java' 카테고리의 다른 글
객체 지향 프로그래밍 Objective Oriented Programming (OOP) (0) | 2022.10.06 |
---|---|
참조타입 (0) | 2022.09.24 |
자바 연산자 (2) | 2022.09.08 |
Variable 변수 (0) | 2022.09.05 |
자바 제어자 (0) | 2022.08.30 |
Comments