Program Java: TUGAS Koding Program NetBeans Pertemuan 7 (Looping For)

Dosen Pengampu : Fince Tinus Waruwu,M.Kom
fincetinus.blogspot.com


 TUGAS Koding Program NetBeans Pertemuan 7 (Looping For)


package dowhile;

public class DoWhile {

    
    public static void main(String[] args) {
        int a1 =0;
        int b1 =1;
        do{
            System.out.println(a1);
            a1=a1 + b1;
        }while (a1 < 10);
    }
}




Tugas (a) Menampilkan Bilangan Genap dan Bilangan Ganjil menggunakan looping for



package dowhilea;

public class DoWhileA {

    public static void main(String[] args) {
        System.out.println("MENCETAK BILANGAN GANJIL");
        int i=1;
        do{
            if( i%2 ==1){
                System.out.println(i);
            }
            i++;
        }while (i<10);
        
      System.out.println("MENCETAK BILANGAN GENAP");     
      int a=1;
      do{
          
          if ( a%2 ==0){
               System.out.println(a);
            }
            a++;
        }while (a<=10);
      System.out.println("");
    }
    
}





Tugas (b) Menampilkan Nama Sebanyak 10x menggunakan looping for


package fora;

public class ForA {

    public static void main(String[] args) {
        int i;
      for(i=1;10>= i;i++)
      System.out.println("Ermi Suryani Nasution");
    }
    
}





Tugas (c) Menampilkan Bilangan Ganjil dan Genap menggunakan looping for


package forb;

public class ForB {

    public static void main(String[] args) {
       int i;
       System.out.println("Bilangan Ganjil");
      for(i=1;i<=10;i++){
          if (i % 2 == 1){
      System.out.println( " "+i+"ganjil");
    } else {
      System.out.println(" "+i+" genap");
  }
}
      
    }
}



Tugas (d ) Menampilkan bilangan Terbesar ke bilangan Terkecil (contoh : 10 9 8 7 6 5 4 3 2 1 0) menggunakan looping for


package forc;

public class ForC {

    public static void main(String[] args) {
       int i;
        for ( i=10; i >=0; i-- ){
        System.out.println(i);
    }
   }
 }





Tugas (e) Menampilkan Hello, STMIK Budi Darma Medan Berurutan menggunakan looping for


package ford;

public class ForD {

    public static void main(String[] args) {
    int i;
      for(i=1;10>= i;i++)
      System.out.println(i+ ". Hello, STMIK Budi Darma Medan");
    }
}





Tugas (f) Menampilkan Segitiga menggunakan looping for

package fore;

public class ForE {

    public static void main(String[] args) {
     System.out.println("SEGITIGA SIKU-SIKU");
       for (int a=1;a<=5; a++){
       for (int b=1;b<=a-1; b++){
           System.out.print("*");
       }
       System.out.println("*");
       }
       
System.out.println("SEGITIGA SIKU-SIKU TERBALIK");
       for (int a=1;a<=5; a++){
       for (int c=1;c<=5-a; c++){
           System.out.print(" ");
       }
       for(int b=1; b<=a-1;b++){
       System.out.print("*");
       }
       System.out.println ("*");
       }
       System.out.print("");
System.out.println("SEGITIGA PIRAMIDA");
       for (int a=1; a<=5; a++){
       for (int c=1; c<=5-a; c++){
           System.out.print(" ");
       }
       for(int d=1; d<=a-1; d++){
       System.out.print("*");    
       }
       for(int b=1; b<=a-1; b++){
       System.out.print("*");
       }
       System.out.println("*");
}

    }
}





Tugas (g) Menampilkan 1-10 menggunakan looping for


package tugaslooping;

public class TugasLooping {

    public static void main(String[] args) {
       int i;
      for(i=1;10>= i;i++)
      System.out.println(i);
    }
   
}




package whilea;

public class WhileA {

    public static void main(String[] args) {
       int i=1;
         while (i<=10){
             System.out.println( i );
             i++;
         }
    }
}



package whileb;

public class WhileB {

    public static void main(String[] args) {
     int i=10;
         while ( i>2 ){
             System.out.println(i);
             i--;
         }
    }
}





package whilecontohkasus;

public class WhileContohKasus {

    public static void main(String[] args) {
        int i=5;
         while ( i>0 ){
             System.out.println("STMIK BUDIDARMA");
             i--;
         }
     }
}




Semoga Bermanfaat....


0 komentar:

Posting Komentar