Selection , Iteration , dan modular (method)
Hello Everyone ,
Selection dibagi menjadi 2 yaitu If dan Switch.
Nested if yaitu if didalam if.
contohnya:
if(________________)
{
if(______________)
{
}
}
p q && || ^
T T T T F
T F F T T
F T F T T
F F F F F
oh iya , kata Koko Sky (dosen) , XOR (^) sama dengan teori JOMBLO --> p|q&!(p&q). hohoho. .
Iteration ada 3 yaitu : while , do while , dan for.
Perbedaan while dan do while yaitu :
Didalam Methods terdapat class , atribut (properti) , dan method/function.
Method atau function ini harus spesifik.
Adapun beberapa coding yang dibahas bersama dalam kelas , yaitu :
contoh 1:
public class Doc1{
public static void main (String args[]){
for(int i=0;i<10;i++){
for(int j=0;j<=1;j++){
System.out.print("*");
}
System.out.println();
}
}
}
output :
*
**
***
****
*****
******
*******
********
*********
**********
contoh 2 :
public class Doc1{
public static void main (String args[]){
for(int i=0;i<10;i++){
for(int j=0;j<=1;j++){
if(j==0 || j==i || i==9){
System.out.print("*");
}else{
System.out.print(" ");
}
}
System.out.println();
}
}
}
output :
*
**
* *
* *
* *
* *
* *
* *
* *
**********
contoh 3 :
NB: untuk membuat bintang seperti contoh 2 itu menjadi ada 10 maka menggunakan Methods.
public class Doc1{
public static void main (String args[]){
for(int i=0; i<10; i++){
Doc1();
}
}
public static void Doc1(){
for(int i=0;i<10;i++){
//j= kolom , i=baris
for(int j=0;j<=1;j++){
if(j==0 || j==i || i==9){
System.out.print("*");
}else{
System.out.print(" ");
}
}
System.out.println();
}
}
}
output :
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
Nama : Yunita Sari , Tan
Kelas : 32PAA
NIM : 1701314034
Thanks ^_^ Happy Learning :)
Binus www.skyconnectiva.com
Selection dibagi menjadi 2 yaitu If dan Switch.
Nested if yaitu if didalam if.
contohnya:
if(________________)
{
if(______________)
{
}
}
p q && || ^
T T T T F
T F F T T
F T F T T
F F F F F
oh iya , kata Koko Sky (dosen) , XOR (^) sama dengan teori JOMBLO --> p|q&!(p&q). hohoho. .
Iteration ada 3 yaitu : while , do while , dan for.
Perbedaan while dan do while yaitu :
- Jika while , kondisi nya di cek terlebih dahulu dan kalau benar baru dijalankan. (kemungkinan ternjadinya while itu 0)
- Jika do while , dijalankan dulu baru di cek kebenaran dari kondisi tersebut. (kemungkinan terjadinya do while itu minimal 1 kali)
Didalam Methods terdapat class , atribut (properti) , dan method/function.
Method atau function ini harus spesifik.
Adapun beberapa coding yang dibahas bersama dalam kelas , yaitu :
contoh 1:
public class Doc1{
public static void main (String args[]){
for(int i=0;i<10;i++){
for(int j=0;j<=1;j++){
System.out.print("*");
}
System.out.println();
}
}
}
output :
*
**
***
****
*****
******
*******
********
*********
**********
contoh 2 :
public class Doc1{
public static void main (String args[]){
for(int i=0;i<10;i++){
for(int j=0;j<=1;j++){
if(j==0 || j==i || i==9){
System.out.print("*");
}else{
System.out.print(" ");
}
}
System.out.println();
}
}
}
output :
*
**
* *
* *
* *
* *
* *
* *
* *
**********
contoh 3 :
NB: untuk membuat bintang seperti contoh 2 itu menjadi ada 10 maka menggunakan Methods.
public class Doc1{
public static void main (String args[]){
for(int i=0; i<10; i++){
Doc1();
}
}
public static void Doc1(){
for(int i=0;i<10;i++){
//j= kolom , i=baris
for(int j=0;j<=1;j++){
if(j==0 || j==i || i==9){
System.out.print("*");
}else{
System.out.print(" ");
}
}
System.out.println();
}
}
}
output :
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
*
**
* *
* *
* *
* *
* *
* *
* *
**********
Nama : Yunita Sari , Tan
Kelas : 32PAA
NIM : 1701314034
Thanks ^_^ Happy Learning :)
Binus www.skyconnectiva.com
Comments
Post a Comment