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 | 29 | 30 | 31 |
Tags
- know
- 형변환
- C++
- Realtime Rendering
- metascore
- by until
- html
- 변수
- for ing
- UE4
- 명세기반테스트
- happen to
- counldn't have
- by any chance
- 게임QA
- ISTQB
- gameQA
- might have p.p
- end up ing
- 코로나19
- sort함수
- 명절 표현
- relif
- it's a good thing
- keep -ing
- 제5인격
- I'm glad
- if조건절
- java
- continue to
Archives
- Today
- Total
Records rather than Memories
논리 연산자 본문
논리 연산자(Conditional Operation)
조건문을 중심으로 더 강력하게 하기 위해 논리 연산자와 비교(boolean)이 사용된다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
package javatutorials.conditionaloperator;
public class AndDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
if (true && true) {
System.out.println("1");
}
if (true && false) {
System.out.println("2");
}
if (false && true) {
System.out.println("3");
}
if (false && false) {
System.out.println("4");
}
}
}
|
cs |
&& : 두 boolean 모두 참이어야 참이다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
package javatutorials.conditionaloperator;
public class LoginDemo3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String id = args[0];
String password = args[1];
if (id.equals("egoing") && password.equals("111111")) {
System.out.println("right");
} else {
System.out.println("wrong");
}
}
}
|
cs |
if문의 중첩문법을 훨씬 간결하게 and를 사용해 활용할 수 있다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
package javatutorials.conditionaloperator;
public class LoginDemo4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String id = args[0];
String password = args[1];
if ((id.equals("egoing") || id.equals("korea") || id.equals("forever"))
&& password.equals("111111")) {
//id 세가지중 하나라도 참이고 password가지 일치하면 right를 출력
System.out.println("right");
} else {
System.out.println("wrong");
}
}
}
|
cs |
|| : 두 boolean 중 하나만 참이어도 참이다.
1
2
3
4
5
6
7
8
9
|
if(!true){
System.out.println(2);
}
if(!false){
System.out.println(2);
} // true가 되어 출력
|
cs |
! : not
'Software > JAVA' 카테고리의 다른 글
[java] for문 (0) | 2019.10.15 |
---|---|
[java] while 반복문 (0) | 2019.10.15 |
GUIApp (0) | 2019.10.15 |
[java] switch문 (0) | 2019.10.14 |
[java] 조건문의 중첩 (0) | 2019.10.14 |
Comments