TUGAS
INDIVIDU
Diajukan
untuk Memenuhi Tugas Mata Kuliah Algoritma
Yang
diampu oleh Nandang Hermanto,s.kom
Oleh
:
Barry
Fadli
SI
12 E
12.12.0275
SISTEM
INFORMASI
STMIK
AMIKOM PURWOKERTO
2012
I. Landasan Teori
1.
While : Pernyataan
while akan dijalankan secara terus-menerus selama kondisi bernilai benar(true).
Bentuk umumnya :
while(
boolean_expression )
{
statement1;
statement2;
. . .
}
2.
Do
While :
Pernyataan do..while, statement dieksekusi setidaknya satu kali.
Bentuk umumnya
:
do{
statement1;
statement2;
. . .
}while(
boolean_expression );
3.
For: Pernyataan
for , melakukan eksekusi pengulangan beberapa kali.
Bentuk
umumnya :
for
(Initialization; LoopCondition; StepExpression){
statement1;
statement2;
. . .
}
4.
If:
Pernyataan If,di lakukan jika syarat if terpenuhi.
Bentuk
umumnya adalah :
IF...ELSE...
Sintaq :
if(boolean_expression)
{
Statement;
}
[else]
{
statement;
}
II. SOAL
1.
Menampilkan Bilangan
1-10 dengan While
2. Menampilkan bilangan 1-10 dengan Do While
3. Menampilkan bilangan 1-10 dengan For
4.
Menampilkan bilangan 10
sampai 1 dengan While
5.
Menampilkan bilangan 10
sampai 1 dengan Do
While
6.
Menampilkan bilangan 10
sampai 1 dengan For
7.
Menampilkan bilangan
kelipatan 3 sampai 30 tanpa kelipatan 5 dengan While
8.
Menampilkan bilangan
kelipatan 3 sampai 30 tanpa kelipatan 5 dengan
Do
9.
Menampilkan bilangan
kelipatan 3 sampai 30 tanpa kelipatan 5 dengan For
10.
Menampilkan perkalian 1
sampai 10
11.
Menampilkan bukit
bintang
12.
III.
Listing Program
1. Menampilkan
Bilangan 1-10 dengan While
Script :
2.
Menampilkan bilangan 1-10
dengan Do
While
Script
:
Output
:
3. Menampilkan bilangan 1-10 dengan For
Script
:
/**
*
* @author barry
*/
public class Bilangan1_10For {
/**
* @param args
the command line arguments
*/
public static
void main(String[] args) {
// TODO
code application logic here
int i;
for
(i=1;i<=10;i++)
{
System.out.println(i);
}
}
}
Output :
4.
Menampilkan bilangan 10
sampai 1 dengan While
Script
:
/**
*
* @author barry
*/
public class Bilangan10Sampai1While {
/**
* @param args
the command line arguments
*/
public static
void main(String[] args) {
// TODO
code application logic here
int i=10;
while
(i>=1)
{
System.out.println(i);
i--;
}
}
}
Output
:
5.
Menampilkan bilangan 10
sampai 1 dengan Do
While
Script :
/**
*
* @author barry
*/
public class
Bilangan10Sampai1DoWhile {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int i=10;
do{
System.out.println(i);
i--;
}while (i>=1);
}
}
Output :
6.
Menampilkan bilangan 10
sampai 1 dengan For
Script :
/**
*
* @author barry
*/
public class
Bilangan10Sampai1For {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int i=0;
for (i=10;i>=1;i--)
{
System.out.println(i);
}
}
}
Output :
7.
Menampilkan bilangan
kelipatan 3 sampai 30 tanpa kelipatan 5 dengan While
Script :
/**
*
* @author barry
*/
public class
Bilangan3Sampai30TanpaKelipatan5 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int i=3;
while (i<=30)
{
if (i%5!=0)
{
System.out.println(i);
}
i+=3;
}
}
}
Output :
8.
Menampilkan bilangan
kelipatan 3 sampai 30 tanpa kelipatan 5 dengan
Do
While
Script :
/**
*
* @author barry
*/
public class Bilangan3Sampai30TnpaKelipatan5Dowhile
{
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int i=3;
do{
if (i%5!=0)
System.out.println(i);
i+=3;
}while (i<=30);
}
}
Output :
9.
Menampilkan bilangan
kelipatan 3 sampai 30 tanpa kelipatan 5 dengan For
Script :
/**
*
* @author barry
*/
public class Bilangan3Sampai30TanpaKelipatan5For
{
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
for(int i=3;i<=30;i+=3){
if(i%5!=0)
System.out.println(i);
}
}
}
Output :
10.
Menampilkan perkalian 1
sampai 10
Script :
package perkalian;
import
java.util.Scanner;
/**
*
* @author barry
*/
public class
Perkalian {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input=new Scanner(System.in);
int i=1,j=1,hasil;
String enter;
for(i=1;i<=10;i++)
{
for(j=1;j<=10;j++)
{
hasil=i*j;
System.out.println(i+"x"+j+'='+hasil);
if(j==10)
{
System.out.println("============");
System.out.print("Lanjut
tekan Enter");
enter=input.nextLine();
if(enter.equals(""))
{
continue;
}
}
}
}
}
}
Output:
11.
Menampilkan bukit
bintang
Script :
/**
*
* @author barry
*/
public class
BukitBintang {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int i=0,j=0;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println("");
}
for(i=5;i>0;i--)
{
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
Output :
IV. Daftar Pustaka
Materi perkuliahan Algoritma
Http://Barryrocket.blogspot.com
Komentar
Posting Komentar