Beruflich Dokumente
Kultur Dokumente
NIM : E31182101
Prodi : Manajemen Informatika
Golongan :D
run:
TRUE 3 x : 11
TRUE 3 y : 5
TRUE 3 :
BUILD SUCCESSFUL (total time: 0 seconds)
run:
if di dalam if Test Seleksi 3
BUILD SUCCESSFUL (total time: 0 seconds)
run:
pertama
kedua
kuartal 1
keluar dari switch
BUILD SUCCESSFUL (total time: 0 seconds)
bulan = 1;
year = 2002;
switch(bulan)
{
case 1: switch(year)
{
case 2002 :
System.out.println("Bulan 1 tahun 2002");
break;
case 2003 : //...
}
case 2: //...
default: //default...
}
}
}
run:
Bulan 1 tahun 2002
BUILD SUCCESSFUL (total time: 0 seconds)
run:
Sebelum while
Setelah while
BUILD SUCCESSFUL (total time: 0 seconds)
run:
Sebelum do
Nilai b : 9
Setelah do8
BUILD SUCCESSFUL (total time: 0 seconds)
class TestIter3
{
public static void main(String[] args) {
int c;
System.out.println("Sebelum for");
for(c=0;c<5;c++)
System.out.println("Nilai c: " + c);
System.out.println("Setelah for");
}
}
Sebelum for
Nilai c: 0
Nilai c: 1
Nilai c: 2
Nilai c: 3
Nilai c: 4
Setelah for
BUILD SUCCESSFUL (total time: 1 second)
public class TestIter4 {
public static void main(String[] args)
{
int d,e;
System.out.println("Sebelum for");
for(d=0,e=6;d<=3 && e>=3;d++,e--)
{
System.out.println("Nilai d : " + d);
System.out.println("Nilai e : " + e);
}
System.out.println("Setelah for");
}
}
run:
Sebelum for
Nilai d : 0
Nilai e : 6
Nilai d : 1
Nilai e : 5
Nilai d : 2
Nilai e : 4
Nilai d : 3
Nilai e : 3
Setelah for
BUILD SUCCESSFUL (total time: 0 seconds)
run:
Sebelum for
Nilai g : 0
Nilai h : 6
Nilai g : 1
Nilai h : 5
Nilai g : 2
Nilai h : 4
Nilai g : 3
Nilai h : 3
Setelah for
BUILD SUCCESSFUL (total time: 0 seconds)
Sebelum while
Nilai a : 9
Nilai a : 8
Nilai a : 7
Nilai a : 6
Nilai a : 5
Nilai a : 4
Nilai a : 3
Nilai a : 2
Nilai a : 1
Nilai a : 0
Setelah while
BUILD SUCCESSFUL (total time: 0 seconds)
run:
Sebelum do
Nilai b : 9
Nilai b : 8
Nilai b : 7
Nilai b : 6
Nilai b : 5
Nilai b : 4
Nilai b : 3
Nilai b : 2
Nilai b : 1
Nilai b : 0
Setelah do
BUILD SUCCESSFUL (total time: 0 seconds)
run:
Sebelum while
Setelah while
BUILD SUCCESSFUL (total time: 0 seconds)
class TestBreak1 {
public static void main(String[] args)
{
System.out.println("Sebelum for");
for(int a=0;a<10;a++) {
if(a==4) break;
System.out.println("Nilai a : "+ a);
}
System.out.println("Setelah for"); }
}
run:
Sebelum for
Nilai a : 0
Nilai a : 1
Nilai a : 2
Nilai a : 3
Setelah for
BUILD SUCCESSFUL (total time: 1 second)
class TestBreak2 {
public static void main(String[] args)
{
System.out.println("Sebelum for");
for(int b=1;b<3;b++) {
System.out.println("Perulangan ke "+ b);
for(int c=0;c<5;c++) {
if(c==2) break;
System.out.println("Nilai c : " + c);
}
}
System.out.println("Setelah for") ;
}
}
run:
Sebelum for
Perulangan ke 1
Nilai c : 0
Nilai c : 1
Perulangan ke 2
Nilai c : 0
Nilai c : 1
Setelah for
BUILD SUCCESSFUL (total time: 1 second)
class TestBreak3a {
public static void main(String[] args) {
boolean status=true; //boolean status=false;
label1:
{
System.out.println("Di dalam blok code label1");
label2 :
{
if(status) break label1;
System.out.println("Di dalam blok code label2");
}
System.out.println("Masih di dalam blok code label1");
}
System.out.println("Di luar blok code label1");
}
}
run:
Di dalam blok code label1
Di luar blok code label1
BUILD SUCCESSFUL (total time: 1 second)
class TestBreak3b
{
public static void main(String[] args) {
//boolean status=true;
boolean status=false;
label1:
{
System.out.println("Di dalam blok code label1");
label2 :
{
if(status) break label1;
System.out.println("Di dalam blok code label2");
}
System.out.println("Masih di dalam blok code label1");
}
System.out.println("Di luar blok code label1");
}
}
run:
Di dalam blok code label1
Di dalam blok code label2
Masih di dalam blok code label1
Di luar blok code label1
BUILD SUCCESSFUL (total time: 1 second)
class TestBreak4 {
public static void main(String[] args) {
System.out.println("Sebelum for");
loop1: for(int x=1;x<3;x++) {
System.out.println("Perulangan ke " + x);
loop2: for(int y=0;y<5;y++) {
if(y==2) break loop1;
System.out.println("Nilai y : "+ y);
} System.out.println("Dalam Loop1 ");
}
System.out.println("Setelah for");
}
}
run:
Sebelum for
Perulangan ke 1
Nilai y : 0
Nilai y : 1
Nilai y : 2
Setelah for
BUILD SUCCESSFUL (total time: 1 second)
class TestBreak5 {
public static void main(String[] args) {
loopA: for(int x =0;x<2;x++) {
System.out.println("Loop A Ke " + x);
}
loop1: for(int x=1;x<3;x++) {
System.out.println("Perulangan ke " + x);
loop2: for(int y=0;y<5;y++) {
// if (y==2) break loopA;
System.out.println("Nilai y : " + y);
}
System.out.println("Akhir program");
}
}
}
}
run:
Loop A Ke 0
Loop A Ke 1
Perulangan ke 1
Nilai y : 0
Nilai y : 1
Nilai y : 2
Nilai y : 3
Nilai y : 4
Perulangan ke 2
Nilai y : 0
Nilai y : 1
Nilai y : 2
Nilai y : 3
Nilai y : 4
BUILD SUCCESSFUL (total time: 1 second)
class TestContinue6 {
public static void main(String[] args) {
int x=10;
System.out.println("Sebelum while");
while(x-->1) {
if(x % 2 == 0) continue;
System.out.println("Nilai x : " + x);
}
System.out.println("Sesudah while");
}
}
run:
Sebelum while
Nilai x : 9
Nilai x : 7
Nilai x : 5
Nilai x : 3
Nilai x : 1
Sesudah while
BUILD SUCCESSFUL (total time: 1 second)
class TestContinue7 {
public static void main(String[] args) {
int x=10,y;
label1: while(x-->0) {
y=0;
while(y++<10) {
if(y > x) {
System.out.println();
continue label1;
}
System.out.print(x*y + " "); } } }}
run:
9 18 27 36 45 54 63 72 81
8 16 24 32 40 48 56 64
7 14 21 28 35 42 49
6 12 18 24 30 36
5 10 15 20 25
4 8 12 16
3 6 9
2 4
1
class TestReturn{
public static void main(String args[]) {
boolean t = true;
System.out.println("Sebelum return");
if (t) return;
System.out.println("Setelah return"); }
}
run:
Sebelum return
BUILD SUCCESSFUL (total time: 1 second)
Tugas Praktikum 5 :
1. public class CetakAngka {
/**
* @param args the command line arguments
*/
public static void main (String [] args)
{
for ( int a=0; a<=5; a++){
for (int b=4; b>=a; b--){
System.out.print(" ");
}
for (int c=1; c<=a; c++){
System.out.print("*");}
for (int d=1; d<=a-1; d++){
System.out.print("*");
}
System.out.println();
}
}
}
run:
*
***
*****
*******
*********
BUILD SUCCESSFUL (total time: 0 seconds)
run:
Program Penampil Bilangan Prima
batas awal : 1
batas akhir : 30
Bilangan prima dari 1 sampai 30 adalah
1
2
3
5
7
11
13
17
19
23
29
BUILD SUCCESSFUL (total time: 1 second)
run:
* * * * *
* * * * *
* * * * *
* * * * *
BUILD SUCCESSFUL (total time: 0 seconds)
4.public class SegitigaSiku{
public static void main(String[] args) {
for(int i = 1; i <= 4; i++){
for(int j = 1; j<i; j++){
System.out.print("*");
}
System.out.println("*");
}
}
}
run:
*
* *
* * *
* * * *
BUILD SUCCESSFUL (total time: 0 seconds)
run:
* * *
* * *
* * *
BUILD SUCCESSFUL (total time: 0 seconds)