Wednesday 7 August 2019

SK T4: JAVA Struktur Kawalan Ulangan For dan While

Contoh Aturcara :

public class LatihanFOR {
 
public static void main(String[] args) {
  int counter = 9;
  for (counter = 9; counter <=72; counter+=9){
    System.out.print(counter + "  ");
  }
 }
}


Contoh output:
9  18  27  36  45  54  63  72  







Contoh Aturcara:

public class LatihanWHILE {
 
 
  public static void main(String[] args) {
  int counter = 9;
 
  while (counter <=72) {
    System.out.print(counter + "  ");
    counter = counter + 9;  
  }
  }
}



Contoh output:

9  18  27  36  45  54  63  72  

0 comments:

Post a Comment

Featured post

Handwritten note... ASK T1 HTML

 

 

SAINS KOMPUTER & ASAS SAINS KOMPUTER Template by Ipietoon Cute Blog Design