Page 43 - PowerPoint Presentation
P. 43

MENULIS ATUR CARA MENGUNAKAN
          1.4                                  STRUKTUR KAWALAN PILIHAN DENGAN
                           1.4.2
                                            MENGGABUNGKAN OPERATOR HUBUNGAN
                                                         DAN OPERATOR LOGICAL
















                          CONTOH ATURCARA                                               OUTPUT


     public class contoh31a {                                                       Nombor ini adalah
                                                                                    integer positif
         public static void main (String [] args) {
             int nombor = 15;


             if (nombor > 0)
                 System.out.println (“Nombor ini adalah integer positif” ) ;


             else
                 System.out.println (“Nombor ini adalah bukan integer positif” ) ;
       }
     }

     public class contoh31b {                                                       Nombor ini adalah
                                                                                    integer negatif
         public static void main (String [] args) {
             int nombor = -7;


             if (nombor > 0)
                 System.out.println (“Nombor ini adalah integer positif” ) ;

             else if (nombor == 0)
                System.out.println (“Nombor ini adalah sifar” ) ;


             else
                 System.out.println (“Nombor ini adalah integer negatif” ) ;


       }
     }








                                                                                                  43
   38   39   40   41   42   43   44   45   46   47   48