if (조건식) {}
: 조건식의 결과는 항상 true 아니면 false여야 한다.
public static void main(String[] args) {
int x = 0;
System.out.printf("x=%d 일 때, 참인 것은 %n", x);
// {} 안에 문장이 하나뿐이면 {}를 생략할 수 있다.
if(x==0) System.out.println("x==0");
if(x!=0) System.out.println("x!=0");
if(!(x==0)) System.out.println("!(x==0)");
if(!(x!=0)) System.out.println("!(x!=0)");
x = 1;
System.out.printf("x=%d일 때, 참인 것은 %n", x);
if(x==0) System.out.println("x==0");
if(x!=0) System.out.println("x!=0");
if(!(x==0)) System.out.println("!(x==0)");
if(!(x!=0)) System.out.println("!(x!=0)");
}
결과값
x=0 일 때, 참인 것은
x==0
!(x!=0)
x=1일 때, 참인 것은
x!=0
!(x==0)