Page 49 - PowerPoint Presentation
P. 49

1.4              1.4.3            MENERANGKAN ALIRAN STRUKTUR

                                                        KAWALAN ULANGAN











                       CONTOH ATURCARA                                               OUTPUT


     public class contoh43 {                                                  1 X 3 = 3
                                                                              2 X 3 = 6
         public static void main (String [] args) {
                                                                              3 X 3 = 9
             int no = 1 ;                                                     4 X 3 = 12
                 do {                                                         5 X 3 = 15
                                                                              6 X 3 = 18
                    System.out.println (no  +  “ X  3  = ” + no  * 3) ;
                                                                              7 X 3 = 21
                    no = no + 1;                                              8 X 3 = 24
             } while ( n <= 12)                                               9 X 3 = 27
                                                                              10 X 3 = 30
         }
                                                                              11 X 3 = 33
     }                                                                        12 X 3 = 36
     public class contoh44 {                                                  6
         public static void main (String [] args) {                           7
             double no ;                                                      9
             double sum;                                                      3
             int counter = 1;
             Scanner scanner = new scanner (System.in);                       6
                 do {                                                         The total is 31.0
                    no = scanner.nextDouble();
                    sum += no ;
                    counter = counter + 1;
                  } while ( counter <= 5)
                 System.out.println (“ The total is ” + sum) ;
         }
     }

     public class contoh45 {                                                  5
         public static void main (String [] args) {                           7
             string input ;                                                   Beza = 2
             Scanner scanner = new scanner (System.in);                       Taip YA untuk teruskan
              int no1;                                                        YA
              int no2;                                                        5
                  do {                                                        9
                    no1 = scanner.nextInt();                                  Taip YA untuk teruskan
                    no2 = scanner.nextInt();                                  t
                    System.out.println (“ Beza = ” + Math.abs (no1 –no2)) ;
                    System.out.println (“Taip YA untuk teruskan”) ;
                    input = scanner.next();
                 } while ( input.equal(“YA”)) ;
            }
     }                                                                                            49
   44   45   46   47   48   49   50   51   52   53   54