RSS Feed

Program While Loop, Do While dan For Loop (Java)

Posted by Restiyanti Labels: , ,

Buat sebuah program yang mencetak nama Anda selama seratus kali. Buat tiga versi program ini menggunakan while loop, do while dan for-loop.

Listing program menggunakan while loop::
public class While {
 public static void main(String args[]){
  int r=0;
  while (r<100){
   System.out.println("RESTIYANTI");
   r++;
  }
 }
}
Listing program menggunakan do-while::
public class DoWhile {
 public static void main(String args[]){
 int r = 0;
 do {
  System.out.println("RESTIYANTI");
  r++;
  } while (r<100);
 }
}
Listing program menggunakan for loop::
public class For {
 public static void main(String args[]){
 int r;
 for (r=0; r<100; r++){
 System.out.println("RESTIYANTI"); 
 }
 }
}

2 comments:

  1. Anonim

    mana out put nya?

  1. Unknown

    Visit Us>thanks for the useful article, improve it again

Posting Komentar