반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- SQL
- google apps script
- Apache
- math
- Excel
- Java
- Google Spreadsheet
- numpy
- array
- Redshift
- PANDAS
- django
- gas
- Kotlin
- Github
- Python
- dataframe
- string
- c#
- hive
- matplotlib
- GIT
- PySpark
- 파이썬
- Tkinter
- Google Excel
- Presto
- PostgreSQL
- list
Archives
- Today
- Total
달나라 노트
Java - if ~ else if ~ else 본문
728x90
반응형
Original source = www.w3schools.com
Java에서의 if문은 다음과 같이 사용할 수 있습니다.
public class JavaIfElse {
public static void main(String args[]) {
if (2 > 1) {
System.out.println("2 is greater than 1.");
}
}
}
-- Result
2 is greater than 1.
public class JavaIfElse {
public static void main(String args[]) {
int a = 1;
int b = 10;
if (a > b) {
System.out.println("A is greater than B.");
}
else {
System.out.println("A is equal to or less than B.");
}
}
}
-- Result
A is equal to or less than B.
public class JavaIfElse {
public static void main(String args[]) {
int x = 1;
int y = 10;
if (x > y) {
System.out.println("x is greater than y.");
}
else if (x == y) {
System.out.println("x is equal to y.");
}
else if (x < y) {
System.out.println("x is less than y.");
}
else {
System.out.println("Error");
}
}
}
-- Result
x is less than y.
Java도 Python처럼 한 줄 if문 기능을 제공합니다.
Syntax는 다음과 같습니다.
(condition) ? "return value when condition is true" : "return value when condition is false"
Java의 한줄 if문 예시입니다.
public class JavaIfElse {
public static void main(String args[]) {
int int_value = 10;
String result = (int_value > 10) ? " greater than 10" : "equal to or less than 10";
System.out.println(result);
}
}
-- Result
equal to or less than 10
728x90
반응형
'Java' 카테고리의 다른 글
| Java - switch ~ case ~ default (0) | 2021.03.11 |
|---|---|
| Java - Math : max, min, sqrt, abs, random (0) | 2021.03.11 |
| Java - For loop : For 반복문 (0) | 2021.03.11 |
| Java - break, continue (0) | 2021.03.11 |
| Java - Array (0) | 2021.03.11 |
Comments