Topik 4A Alpro - Algoritma Utk Branching Dan Looping
Topik 4A Alpro - Algoritma Utk Branching Dan Looping
ALGORITMA PERCABANGAN
DAN PERULANGAN
ALGORITMA
2
https://www.edrawsoft.com/flowchart-definition.html
Integrating academic excellence and humanistic values
Universitas Sanata Dharma
Pseudocode
Mulai
Baca suhu
IF suhu < 32
Tampilkan “Below freezing”
ELSE
Tampilkan “Above freezing”
Selesai
Program Java
public class CekSuhu {
public static void main(String[] args) {
int suhu;
suhu = 20;
if (suhu < 32)
System.out.println("Below freezing ");
else
System.out.println("Above freezing ");
}
}
https://problemsolvingwithpython.com/09-Loops/09.04-Flowcharts-
Describing-Loops/
Integrating academic excellence and humanistic values
https://www.programiz.com/java-programming/for-loop
Universitas Sanata Dharma
https://problemsolvingwithpython.com/09-Loops/09.04-Flowcharts-
Describing-Loops/
Integrating academic excellence and humanistic values
Universitas Sanata Dharma
Pseudocode
Mulai
Baca masukan bilangan positif n
While n < 0
baca masukan bilangan positif n
End while
Tampilkan “Positive”
Selesai
https://problemsolvingwithpython.com/09-Loops/09.04-Flowcharts-
Describing-Loops/
Integrating academic excellence and humanistic values
https://www.programiz.com/java-programming/for-loop
Universitas Sanata Dharma
Program Java
public class CekPositif {
public static void main(String[] args) {
int n;
Scanner sc=new Scanner(System.in);
System.out.println(“Masukkan n: ”);
n = sc.nextInt();
While (n < 0) {
System.out.println(“Masukkan n”);
n = sc.nextInt();
}
System.out.println(“Positive”);
}}
https://problemsolvingwithpython.com/09-Loops/09.04-Flowcharts-
Describing-Loops/
Integrating academic excellence and humanistic values
https://www.programiz.com/java-programming/for-loop
Universitas Sanata Dharma
https://www.tenouk.com/clabworksheet/labworksheet7_1.html
https://www.tenouk.com/clabworksheet/labworksheet7_1.html
Program Java
public class CekAngka {
public static void main(String[] args) {
int i=2;
While (i <=6) {
System.out.println(i+1);
i=i+2;
}
}
}
https://www.tenouk.com/clabworksheet/labworksheet7_1.html
https://stackoverflow.com/questions/43697634/showing-nested-for-
loops-in-a-flowchart https://www.tenouk.com/clabworksheet/labworksheet7_1.html
Integrating academic excellence and humanistic values
Universitas Sanata Dharma
Flowchart Pseudocode
Mulai
i=1
While I <= 10
cetak i
j=i+1
While j <=10 :
Cetak j
j=j+1
End while
i=i+1
End while
Selesai
https://www.tenouk.com/clabworksheet/labworksheet7_1.html
Integrating academic excellence and humanistic values
Universitas Sanata Dharma
import java.util.Scanner;
int count = 1;
while ( count <= N )
{
sumAll = sumAll + count ;
if ( count % 2 == 0 )
sumEven = sumEven + count ;
else
sumOdd = sumOdd + count ;
count = count + 1 ;
}
}
System.out.println( "\tSum of odd : " + sumOdd ); Integrating academic excellence and humanistic values
}
Universitas Sanata Dharma
17