* IF : boolean형의 결과를 가지고 조건식이 있어야 하며, 그 조건식의 결과로 수행하는 문장을
        결정한다.


1.
class IfEx1 {
   public static void main(String[] args) {
      int a = 5;
      if(a > 0) {
         System.out.println("0보다 크다");
      }
   }
}


2.
class IfEx1 {
   public static void main(String[] args) {
      int a = 5;
      if(true) {
         System.out.println("True영역");
      }
   }
}


3.
class IfEx1 {
   public static void main(String[] args) {
      int a = 5;
      if(a > 0) {
         System.out.println("True영역");
      }
      else {
         System.out.println("False영역");
      }
   }
}


4.
class IfEx1 {
   public static void main(String[] args) {
      int a = 2;
      if(a > 0) {
         if(a > 3) 
            System.out.println("a는 3보다 크다.");         
         else 
            System.out.println("a는 3보다 작다.");         
      }
      else 
         System.out.println("a는 0보다 작다");      
   }
}


5.
class IfEx1 {
   public static void main(String[] args) {
      int a = 2;
      if(a > 10)
         System.out.println("a는 10보다 크다");
      else if(a > 5)
         System.out.println("a는 5보다 크다");
      else if(a > 3)
         System.out.println("a는 3보다 크다");
      else if(a > 0)
         System.out.println("a는 0보다 크다");
      else
         System.out.println("a는 0보다 작다");
   }
}

a는 0보다 크다


6.
class IfEx1 {
   public static void main(String[] args) {
      int score = 87;
      String result = "";
      if(score >= 90) {
         result = "A";
         if(score > 95)
            result +="+";
      }
      else if(score >= 80) {
         result = "B";
         if(score > 85) 
            result +="+";         
      }
      else
         result = "F";
      System.out.println("당신의 학점은 "+result);
   }
}

당신의 학점은 B+

'Programming > Java' 카테고리의 다른 글

For  (0) 2011.01.06
Switch  (0) 2011.01.06
연산자  (0) 2011.01.05
프로모션 , 디모션  (0) 2011.01.05
System.out.println()  (0) 2011.01.04

+ Recent posts