if문_1

ㅇㅇ2018.06.24
조회7
public class FlowEx1 {

public static void main(String[] args) {
int x = 0;
System.out.printf("x=%d 일 때, 참인 것은 %n", x);
if(x==0) System.out.println("x==0"); // true √
if(x!=0) System.out.println("x!=0"); // false
if(!(x==0)) System.out.println("!(x==0)"); // ture이지만 ! 때문에 false
if(!(x!=0)) System.out.println("!(x!=0)"); // false 이지만 ! 때문에 ture √
System.out.println();


x = 1;
System.out.printf("x=%d 일 때, 참인 것은%n", x);
if(x==0) System.out.println("x==0"); // false
if(x!=0) System.out.println("x!=0"); // true √
if(!(x==0)) System.out.println("!(x==0)"); false 이지만 ! 때문에 true √
if(!(x!=0)) System.out.println("!(x!=0)"); true이지만 ! 때문에 false
//!는 not, !(x == 0)과 x != 0 이 똑같다 <(!)는 논리 부정 연산자>
//★출력값이 true이면 false로 출력, 출력값이 false이면 true로 출력
}
}

출력
x=0 일 때, 참인 것은 
x==0
!(x!=0)


x=1 일 때, 참인 것은
x!=0
!(x==0)